#1 2022-11-08 00:41

jogiwer
Member
From: Germany
Registered: 2022-11-05
Posts: 66

Global variables for scripts and other proposals

What a great peace of software. For me regular expressions are a must for working with strings.

Another aspect for a good renaming utitlity is the access to media-tags. This is implemented for many types of media!.

But as allways time does not stand still and there get new filetypes into focus. So actually you can't handle HEIC files directly. As I understood this would be possible the time a usable pascal-lib will occur.

Thanks to PascalScript there is at least a solution using external tools. But doing this on many files lacks of the speed the internal solution could offer ...
I am using exiftool to get the information I need. exiftool as perl implementation would have the most speed by doing many files in on go. Here I have to do many calls - i.e. one call for every file not handled by ReNamer itself.

If my renaming scheme used to add meta-tags with two different rules I now have to call the tool mutliple times.

In your cookbook I can find solutions to initialize a script to have values set the time I'll get again into that script. But what I am looking for is a way to pass a result from one script/rule to another. Actually I could only imagine temporary files, registry, clipboard or as part of the filename. Each of these would involve a proper parsing ...

  1. could you set up a way of global variables which could be used by every script

  2. I would like a way to access a list of all files so these could be put into a single call of exiftool (or alike)

  3. If working on a group of files (grouped by same basename and different extensions) normally a renaming should happen in a way that the name is build with one file. For further files no more replacements or calls of external tools should be needed. But how could I achive this. The resulting name may be found via global variables but skipping all steps/rules for file b there has to be something new ...

  4. preview might take a while using complex rules with scripts and/or external tools. I allready read that a process bar is hard to implement. Nevertheless I'd like to add:

    1. Next to showing the progress there should be also a way to stop the step

    2. It could also help to add the new names to the list as they are build. So one could see the progress in the list which should be scrollable while in the step.

    3. As new names are added one could check the quality of the renaming and might want to stop the task on bad results

    4. Maybe it is an idea to put a specal command to PascalScript that could do some updates to the gui, handle any cancel request ...
      Just like a dialog but it should not hold the flow or need action for every single file.

Last edited by jogiwer (2022-11-19 22:41)

Offline

#2 2022-11-08 01:02

jogiwer
Member
From: Germany
Registered: 2022-11-05
Posts: 66

Re: Global variables for scripts and other proposals

Just found the application functions. So getting a list of original names a doing clustered calls to exiftool (as an example) should be managable big_smile

Offline

#3 2022-11-09 15:42

den4b
Administrator
From: den4b.com
Registered: 2006-04-06
Posts: 3,367

Re: Global variables for scripts and other proposals

1. could you set up a way of global variables which could be used by every script

As you rightly pointed out, one can use temporary files and clipboard to store globally accessible information. For example, see FileReadContent/FileWriteContent and GetClipboardText/SetClipboardText functions in Pascal Script.

We can also implement in-memory storage, as a more efficient mechanism for exchange of information between scripts, something like:

procedure SetScriptVar(const Name, Value: String);
function GetScriptVar(const Name: String): String;

Would that help?

2. I would like a way to access a list of all files so these could be put into a single call of exiftool (or alike)

See GetAllFiles and GetMarkedFiles functions in Pascal Script.

3. If working on a group of files (grouped by same basename and different extensions)...

This is a tricky one. There have been a few discussions on this topic, but solutions are usually very problem-specific and difficult to generalise.

For example, you could try something like this:

1. Move all files with the same basename to a dedicated folder, per basename.
2. Rename folder names according to your specification.
3. Use the parent folder name to rename all contained files.

4. preview might take a while using complex rules with scripts and/or external tools.

It is on the "to do" list, but with a low priority.

Offline

#4 2022-11-10 23:00

jogiwer
Member
From: Germany
Registered: 2022-11-05
Posts: 66

Re: Global variables for scripts and other proposals

1. could you set up a way of global variables which could be used by every script

...

We can also implement in-memory storage, as a more efficient mechanism for exchange of information between scripts, something like:

procedure SetScriptVar(const Name, Value: String);
function GetScriptVar(const Name: String): String;

Would that help?

Oh yes. I was hoping that there was a "pascal way" such as declaring variables in a "global" block or so. But a function-set like this would be great.

  • Using files seem time consuming and one has to take care of collisions, cleaning up ...

  • Clipboard could/would clash with the user doing other actions while ReNamer is busy!

  • Most of your code examples work with WideString - especially for filename-parts. So this should be available.

  • I would like to transfer the result of a run of exiftool. I can imagine that some data structures like arrays could be useful here.
    These could be put here by joining to a (Wide)String which involves parsing or splitting afterwards.
    Are there any methods to handle serializing/unserializing via json, xml, php-arrays or csv? Especially as exiftool could generate this as output.

2. I would like a way to access a list of all files so these could be put into a single call of exiftool (or alike)

See GetAllFiles and GetMarkedFiles functions in Pascal Script.

Yes, found this already. As stated at the comment before your answer wink

3. If working on a group of files (grouped by same basename and different extensions)...

This is a tricky one. There have been a few discussions on this topic, but solutions are usually very problem-specific and hard the generalise.

For example, you could try something like this:

1. Move all files with the same basename to a dedicated folder, per basename.
2. Rename folder names according to your specification.
3. Use the parent folder name to rename all contained files.

Ok - I think this would take three passes and for this three different rulesets.

As a quick example I have two files "abc.JPG" and "abc.MOV". Actually I am running the whole ruleset on both files. Inserting metatags won't succeed for the MOV. Here is where PascalScript comes in charge. By looking to the filesystem I find the JPG and than I let exiftool get the wanted tags.

So here I am doing the whole process twice. On the JPG somewhat quicker as I have to check the filesystem and make a call to exiftool.
With the correct order of files I could have `SetScriptVar` the name of the JPG and use it for the MOV but:

I can't skip all the rules. Only with PascalScript I could check for this but a simple "insert" would still be executed.

But what about this approach:

  1. A new "rule" for setting labels. It does nothing but just exists. Or maybe it could do something but switched off it could be used by

  2. a method for PascalScript and/or another rule for skipping.
    You could skip a number of rules or jump (goto) a label-rule.
    With this one could code something like "if name is done allready then use it and skip to the label <cleanup>"

4. preview might take a while using complex rules with scripts and/or external tools.

It is on the "to do" list, but with a low priority.

Acknowledged cool

Last edited by jogiwer (2022-12-02 22:10)

Offline

#5 2022-12-06 23:42

jogiwer
Member
From: Germany
Registered: 2022-11-05
Posts: 66

Re: Global variables for scripts and other proposals

Hi Denis & all,
I just want to sum up the open questions from this thread and some others - as I have created many open ends.

As I don't want to bring all of them to the top I thougt it would help to have them mentioned in one post. But feel free to answer at the best fitting spot.

I) From this thread:

  1. Are you going to provide us with functions like SetScriptVar/GetScriptVar?
    And if yes - shortly or with lower priority?

  2. Any chances to get a goto like skipping? This would need target labeling, a method for activating the skip as well as the awareness of the native (non Pascal Script) rules that they should do nothing on skip.

  3. Logging - for this I came up with onother thread.

II) Poor mans way to watch the progress

  1. Have you spotted this?
    Here every <n> files a dialog pops up and shows the new names - sort of logging and progress.

  2. As there are functions to read the names of other files  - is there a chance to get access to the column "new name" of them?
    For this progress info it would help to access the names so there would be no need to accumulate this in variables.
    For the problem with filegroups it could help to get the calculated name of previous files.

III) Milliseconds from JPEGs

  1. Could you think of a way to extract the millis from JPG file through :EXIF_Date: or a new :EXIF_SubSecTime: if and only if this value is available. At the moment the only way to get this is the use of external tools ...

IV) Got some logging
Logging to external files is achievable. But to get a good amount of informations in different log levels one has do add a lot of Pascal Script rules.

  1. Did you already think about doing some logging out of the rules?

  2. This could be send to files but in my opinion a text frame inside ReNamer would be best. Maybe also a status line.

  3. But maybe this frame would also need to be implemented with subprocesses ...

  4. To keep the visualization out of ReNamer logging could also do some by network calls.

V) Problem with WideToOem

  1. Any idea why WideToOem didn't change the call of exiftool?

VI) Questions on Pascal Script

  1. Do you know of any sources where the feature set of Pascal Script is documented?

  2. Could you suggest an IDE for developing these scripts? Final test surely could only be run inside ReNamer but an IDE could also assist in some ways by code completions and so on ...

Last edited by jogiwer (2022-12-06 23:43)

Offline

#6 2022-12-10 22:25

den4b
Administrator
From: den4b.com
Registered: 2006-04-06
Posts: 3,367

Re: Global variables for scripts and other proposals

Are you going to provide us with functions like SetScriptVar/GetScriptVar?

Yes. Global variables have been implemented and now available for testing in 7.4.0.2 Beta.

Any chances to get a goto like skipping?

No. It would have to be implemented upstream in the Pascal Script component.

As a professional programmer, I would advise strongly against using goto style programming.

See Spaghetti code, XKCD goto, and use Google to understand the evils hiding behind goto style programming.

Logging

Proper logging is planned, but low priority.

Watch the progress

Once again, this is planned, but requires significant rework of the application into a multi-threaded design.

Is there a chance to get access to the column "new name" of them?

Currently, the new name is only accessible via the FileName variable in Pascal Script for each processed file.

A more general way of accessing new names is being considered.

Milliseconds from JPEGs

We'll have to wait until one of mainstream EXIF libraries is properly integrated into ReNamer.

Any idea why WideToOem didn't change the call of exiftool?

OEM encoding/decoding routines are meant for handling console output only.

See the full answer in the original thread.

Do you know of any sources where the feature set of Pascal Script is documented?

The Pascal Script component supports a subset of features and syntax of Delphi / Free Pascal, but nobody has actually documented it properly.

On top of that, every software that uses the Pascal Script component has its own collection of extra functions and types.

See ReNamer's Pascal Script documentation.

Could you suggest an IDE for developing these scripts?

You can use Lazarus IDE, a free cross-platform visual integrated development environment for Free Pascal compiler.

Offline

#7 2022-12-11 01:28

jogiwer
Member
From: Germany
Registered: 2022-11-05
Posts: 66

Re: Global variables for scripts and other proposals

Thanks for all of your replies!

den4b wrote:

Are you going to provide us with functions like SetScriptVar/GetScriptVar?

Yes. Global variables have been implemented and now available for testing in 7.4.0.2 Beta.

I surely will give it a try!

In my workaround I was writing the values to a file after url-encoding them. With this I wanted to assure that all possible values could be stored.
Your new functions don't support WideString - will this be sufficient? I guess it will as in that case UTF-16 will be transcoded to UTF-8 without any loss ...

Edit: noticed that the functions take and return "Variant" - so this should be sufficient in any case!

den4b wrote:

Any chances to get a goto like skipping?

No. It would have to be implemented upstream in the Pascal Script component.

As a professional programmer, I would advise strongly against using goto style programming.

See Spaghetti code, XKCD goto, and use Google to understand the evils hiding behind goto style programming.

I totally agree with you about goto style programming.

But maybe I have choosen the wrong word. In this case I would like to change the workflow of the processing of the rules. A Pascal Script rule might get the target name from anywhere. After this no further rules are needed (for example a call of exiftool). I would like to skip all (or a certain set) of the following rules.

den4b wrote:

LoggingProper logging is planned, but low priority.

den4b wrote:

Watch the progress

Once again, this is planned, but requires significant rework of the application into a multi-threaded design.

As you are writing it. I just assumed that logging differs from a progress bar ... but actually one is with text and the other would get some kind of gauge ...

den4b wrote:

Is there a chance to get access to the column "new name" of them?

Currently, the new name is only accessible via the FileName variable in Pascal Script for each processed file.

A more general way of accessing new names is being considered.

In most cases I won't be in the last rule. So even the FileName variable I can access won't give me the resulting new name cool

And as you surely understood - I'd like to get the new names of already processed files.

Edit: with a Pascal Script rule at the end I can use SetGlobalVar() to store a TWideStringArray with all the processed FileName values.

den4b wrote:

Do you know of any sources where the feature set of Pascal Script is documented?

The Pascal Script component supports a subset of features and syntax of Delphi / Free Pascal, but nobody has actually documented it properly.

On top of that, every software that uses the Pascal Script component has its own collection of extra functions and types.

See ReNamer's Pascal Script documentation.

The describes exactly the result of my investigations.

den4b wrote:

Could you suggest an IDE for developing these scripts?

You can use Lazarus IDE, a free cross-platform visual integrated development environment for Free Pascal compiler.

I'll have a look at it - though it seems to be a big tool for some scripting ...

Last edited by jogiwer (2022-12-12 20:02)

Offline

#8 2022-12-12 22:45

den4b
Administrator
From: den4b.com
Registered: 2006-04-06
Posts: 3,367

Re: Global variables for scripts and other proposals

jogiwer wrote:

Your new functions don't support WideString - will this be sufficient? I guess it will as in that case UTF-16 will be transcoded to UTF-8 without any loss ...

Correct.

As noted in the related thread, ReNamer 7.x branch introduced major changes in the handling of string encoding. The String (AnsiString) type became code page aware and uses UTF8 encoding by default. Conversions between WideString and String types are performed automatically.

jogiwer wrote:

noticed that the functions take and return "Variant" - so this should be sufficient in any case!

Correct.

The values of global variables are Variant typed, so they can store pretty much any type.

jogiwer wrote:

Could you suggest an IDE for developing these scripts?

Lazarus IDE is pretty heavy indeed.

There are lightweight alternatives, like Notepad++ with basic syntax highlighting, and OmniPascal extension for Visual Studio Code.

Last edited by den4b (2022-12-12 22:50)

Offline

#9 2022-12-13 19:04

jogiwer
Member
From: Germany
Registered: 2022-11-05
Posts: 66

Re: Global variables for scripts and other proposals

Notepad++ is actually the tool I'm setting up files to be included by {$INCLUDE ...}.

But OmniPascal looks like it is worth a trial. Thanks for the hint (and all the insights).

Offline

Board footer

Powered by FluxBB