Page 1 of 1
Apple pie simple script fails
Posted: 28 Mar 2012 16:03
by aurumdigitus
Just when I've managed to get some reasonably decent scripts to run custom toolbar buttons this code fails and the problem eludes.
Help requested.
"Some days you're the windshield - some days you're the bug."
Code: Select all
// Intent: Duplicate selected file then change the "-01" to COPY
#163;
rename s, "-01/ COPY";
Re: Apple pie simple script fails
Posted: 28 Mar 2012 16:21
by TheQwerty
Couple possible reasons:
- #163 could be running in the background and XY attempts the rename before the copy has completed.
- The new item as a result of #163 isn't automatically selected.
Why not use new instead?
Code: Select all
New("<curbase> COPY.<curext>", 'file', "<curitem>");
Re: Apple pie simple script fails
Posted: 28 Mar 2012 16:50
by Stefan
>Why not use new instead?
Because he wants an copy of an file, not the name only.
EDIT:
ohh, you are right, new() can do this too:
new(name, [type=file|dir], [source], [rename=|r])
overlooked, sorry
- - -
What if you e.g. already have an (even modified?) -01 file and your fresh copy is called -02 now?
Then this script would still rename the maybe older -01 to COPY instead of the newer -02.
Best would be to use "copyas" here.
copyas [pattern], [targetpath], [itemlist]
itemlist: [optional] ......If empty then the current list selections are copied.
Example:
Code: Select all
copyas "* COPY.?";
//or even better with error handling in case more then one file is selected:
if (get("CountSelected") == 1) { copyas "* COPY.?"; }
//or
if (get("CountSelected") == 1) { copyas "* COPY.?"; } else { msg "Please select ONE file only!";}
HTH?

Re: Apple pie simple script fails
Posted: 28 Mar 2012 17:15
by aurumdigitus
Genuine thanks to both TheQwerty and Stefan for their insightful and elucidated help without losing patience. Glad for having chosen chemistry not computers as atomic structure seems easier to comprehend.
You generated the desired result albeit by altogether different commands.
Robert Burns might as well have been a programmer when he wrote,
"The best laid schemes o' Mice an' Men, Gang aft agley."
