Page 1 of 1

send to clipboard with additional editing

Posted: 18 Apr 2018 17:38
by suslo
i've spent several hours on a very easy task (for those who have big experience) but didn't succeded due to absolute lack of knowledge
so i ask for the help. example with 4 selected files:

Code: Select all

05 - Complicated Heart.flac
06 - 25 Minutes.flac
07 - You Keep Me Running.flac
08 - Out Of The Blue.flac
it is necessary to add #113 (item bases to clipboard) to my script but without first 5 characters of each title
so the desired clipboard content should be:

Code: Select all

Complicated Heart
25 Minutes
You Keep Me Running
Out Of The Blue
i tried different approaches and bizarre combinations. in my consciousness everything is mixed up already so i only may mention various pieces of text from the help/net/forum that were tested in this or that way:
copytext "<curbase>"; copytext "<selitems <crlf>>", a;
copytext "<selitems <crlf>><curbase>";
copytext "<curbase><selitems <crlf>>";
#113 "<replace( , " - ", 1, 1, , )>";
Get('SelectedItemsNames');
folderreport("files:{fullname}<curbase>", "clipboard");

Re: send to clipboard with additional editing

Posted: 18 Apr 2018 17:48
by highend
E.g.:

Code: Select all

    $items = <get SelectedItemsNames <crlf>>;
    // Now we are removing the extension from each item
    $items = regexreplace($items, "\.[^.]+?$");
    // Now we are cutting off the first 5 characters for each item
    $items = regexreplace($items, "^(.){5}(.*)(?:\r?\n|$)", "$2<crlf>");
    copytext $items;
Btw, you really need to look those code snippets up in the help file, otherwise you won't learn a lot...
<curbase> for example, is not for multiple selected files, but only for one. Otherwise it's empty...

Re: send to clipboard with additional editing

Posted: 18 Apr 2018 18:01
by highend
@jupe

I know you're versions are meant to be corrected by the people who try them out, so... :mrgreen:

Code: Select all

copytext($res)
copytext is not a function, no return value, no parentheses...

It's valid code for what was asked for but please do not use it if want to handle a lot of selected files with it
A lot = 10k+
regexes are easily a hundred times faster than a foreach loop with a lot of items to process...

Re: send to clipboard with additional editing

Posted: 18 Apr 2018 18:19
by highend
@suslo

Because both code examples don't take folders into account (if you'd ever need to process those as well)...

This would handle this gracefully (by not cutting off folders with dots in it):

Code: Select all

    $items = report("{basename}{Dir \}<crlf>", <get SelectedItemsPathNames |>);
    // Now we are cutting off the first 5 characters for each item
    $items = regexreplace($items, "^(.){5}(.*?)(?:\r?\n|$)", "$2<crlf>");
    // Now treat folders (they have a trailing backslah atm)
    $items = regexreplace($items, "\\$");
    copytext $items;

Re: send to clipboard with additional editing

Posted: 18 Apr 2018 18:44
by suslo
thank you, highend and Jupe

a) highend, seemingly i should choose the last version of your scripts though both of them work
folders will not be a problem because this thread improved my new modest script (which i began to create ~12 hours ago) where folders are not in use at all
in several words: as much as i can i'm trying to automate the process of converting the music albums from separate tracks to images

b) back to this topic: almost everything i tried, i took from the help during long reading
concerning <curbase>: yes, very soon i understood that it is no helper for me because it was only working with the last selected file
and i was really wondering: where is the <curbases>? or something like that

c) when preparing my posts, i don't see the 'off-topic' code so i dare to ask openly:
do you think that the situation with wrong sort order described here has no solutions?

Re: send to clipboard with additional editing

Posted: 18 Apr 2018 19:08
by highend
where is the <curbases>?
It's report() with the "{basename}" template... Not every possible variable exists...

c.) I didn't understand your (Compiliation... Split..., etc.) so without showing a real word
example -> Nothing to add to that topic