Hacking Image Titles
Hi all,
I have read through Leonie, Old Toad and Ken's post on sorting photos and titles. I have used several AppleScripts from various posts as well.
At the moment, I have some post-Aperture photos which was batched as
Photos - 1
Photos - 2
Photos - 3
...
Photos - 11
Photos - 12
Photos - 13
Sorting by title would see these sorted by Photos - 1, 10, 100, 101, 102...
I have tried hacking some of the scripts on this site but could not get it to work... Could I get some expert help from this site please?
on run {input, parameters}
tell application "Photos"
activate
set imageSel to (get selection)
if imageSel is {} then
error "Please select an image"
else
set n_digits to 2
if (count of imageSel) is greater than 99 then set n_digits to 3
end if
repeat with im in imageSel
set myFileName to filename of im as string
set tmpFileName to (the reverse of every character of myFileName) as string
set myDash to (length of myFileName) - the (offset of "- " in tmpFileName)
set myDot to (length of myFileName) - the (offset of "." in tmpFileName)
set ntext to characters (myDash of myFileName) thru (myDot of myFileName)
repeat while (the length of ntext < n_digits)
set ntext to "0" & ntext -- this adds leading zeros
set myLength to (length of myFileName) - the (offset of " - " in tmpFileName)
set the name of im to characters 1 thru myLength of myFileName & " - " & ntext as text
end repeat
end repeat
end tell
end run
It usually fails at The action “Run AppleScript” encountered an error: “Can’t get myDash of "Photo - 3.tiff".”
Any ideas or suggestions please?
Thanks,
macOS High Sierra (10.13.2)