Batch Changing in Photos, Tweaks to other Scripts
This is not a question but a possible answer(s).
First I must give credit to users of this forum, léonie and Old Toad for sharing their AppleScript for doing some of the things that were easily done in iPhoto. For those of you lamenting for iPhoto, keep in mind that they never have fixed the memory leak in that program but I do understand in the sense that Photos is missing many things that we used and liked. One of the most important was being able to batch edit images. The answer for the power users is AppleScript or Automator or the combination of the two. I ended up using a combination. Bear with me here... AppleScript has changed a lot since OS X and keeps on changing with new versions of the OS. I can't even write a script to open what is in the Clipboard (back in the day, when you did a cmd-c or cmd-x, it went to the clipboard and you could open a window of the clipboard). Needless to say, since it has been changing so much, some us who use AppleScript now have to adapt.
Automator is new, too new. It doesn't have nearly the capabilities as the old Applescript. Back in the day when I was learning AppleScript (in OS 9 BTW), I was able to create a Video Poker Game using only AppleScript!
I know some of you guys (I use guys to include gals) either like AppleScript or Automator and fight to use both. The one biggest thing I have noticed that when an AppleScript is run in using Automator, it seems to run smoother and more consistently. I made an old script a little newer and tried to run it via SriptEditor App. It would work once or even twice and then do strange things afterwards. If I run it via Automator, it works everytime.
léonie and Old Toad have been great in sharing and in that vane, I would like to share also. Here are three scripts that should be run through Automator as a Workflow. Workflow seems to me the most stable of all the choices given. I've tried Services and compiling to an App and it is buggy to say the least. So again, create a work flow, add the "Run AppleScript" via the Script Menu. If you don't have that menu, do this. Open "ScriptEditor." It is in your Utilities folder, which is in your Applications folder. Create a new script and copy and paste the following:
tell application "Script Editor"
activate
tell application "System Events"
keystroke "," usingcommand down
end tell
end tell
What should have happened the Preference window in ScriptEditor should have Opened up. Along the top "General" should be high-lited. Put a check mark in the box for "Show Script Menu in Menu Bar." You will see a new icon in your menu bar. Click on it an you can open Script folders. One for the app you are currently in and one for you only and one for all the users of the computer. I save my stuff into "User Scripts Folder." Within that folder, you will see another folder called "Applications." Open it and you will see specific Application folders. These are the places you put your workflow you make in Automator for specific applications. In this case, it would be a fold called "Photos." You should already have one if you've switched over to Photos. Go back to the ScriptEditor and you can quit it without saving. Remember that these scripts are run in Automator, not in ScriptEditor nor the older AppleScriptEditor. I am also running OS X 10.10.4. All this is important because Apple keeps on changing AppleScript and Automator behavior, so your milage may vary.
This one just changes your image's name to the image's file name without the extension. You select as many images as need, though I haven't test using thousands of images. Again, I've used much if not all of the scripts that léonie and Old Toad made. I've only added small amount to it and some more explanation as to what is happening
on run {input, parameters}
tell application "Photos"
activate
if imageSel is {} then -- forgetting to select image(s)
beep -- sometimes a noise before you walk away is a way to get your attention, you can delete this line if you get beeped too often
tell application "Finder" -- got to go here to display a dialog
activate
display dialog "Please Select Images in Photos to Rename as the File Name without the Extension" -- this string can be changed to whatever you need to say
end tell but don't delete the quote marks
else
repeat with im in imageSel
set myFileName to filename of im as string -- this gets the name of the filename for the image
set tmpFileName to (the reverse of every character of myFileName) as string -- this flips it around in a temp variable
set myLength to (length of myFileName) - the (offset of "." in tmpFileName) -- this counts letters in the filename and then subtracts the count of the extention
set the name of im to characters 1 thru myLength of myFileName as text -- This sets the name in Photos to the file name minus the extention (.jpg, .jpeg, .gif...etc)
end repeat -- This is so that this script does all the Photos you selected.
end if
end tell
end run
-- At 'end run' is the end of the script. The next one does a bit more. It does the same thing above but also add trailing numbers at the end of the name. Unlike some of the other scripts, it will not ask you for how many trailing digits you want to start. It will always default to 2 digits (it will start at image - 01) unless you pick more than 100 images, then it will start with 001.
on run {input, parameters}
set n_digits to 2 -- how many digits for the appended number as a default as in 01, 02...etc. You can set this to 1 so there are no leading zeros
tell application "Photos"
activate
set counter to 1 -- This is the number used for the first image
set imageSel to (get selection) -- get selected images
if imageSel is {} then -- forgetting to select image(s)
beep -- sometimes a noise before you walk away is a way to get your attention
tell application "Finder" -- got to go here to display a dialog
activate
display dialog "Please Select Images in Photos to Rename and Number and re-start this Script" -- this string can be changed to whatever you need to say
end tell
else
if (count of imageSel) is greater than 99 then -- if more than 100. You can also removed this so there are no leading zeros.
set n_digits to 3 -- ... set digits to 3 as in 001, 002 ... etc.
-- you can add more if's or else if you want more than 3 digits but if you do nothing, it will give enough digits, it just won't show lower digits with leading zeros if you have over 999 images you want to number as in 0001.
end if -- delete this if you deleted the previous if statement. Of course you need to delete everything in-between.
-- I suggest that if you need to remove stuff, comment it out using the dashes just in case you want it back
-- This next part came with the help I got from "old toad" from this Internet page: https://discussions.apple.com/docs/DOC-8481
repeat with im in imageSel
set ntext to the counter as text -- This numbers the image
repeat while (the length of ntext < n_digits) -- add leading zeros for numbering
set ntext to "0" & ntext -- this adds leading zeros
end repeat
tell im
set myFileName to filename of im as string -- this gets the name of the filename for the image
set tmpFileName to (the reverse of every character of myFileName) as string -- this reverses the file name and puts a temp variable, a fancy way of saying holder
set myLength to (length of myFileName) - the (offset of "." in tmpFileName) -- this counts letters in the filename and then subtracts the count of the extention
set the name of im to characters 1 thru myLength of myFileName & " - " & ntext as text -- This sets the name in Photos to the file name minus the extention (.jpg, .jpeg, .gif...etc) adds " - " plust leading zeros if any and then the number of the Photo
set counter to counter + 1 -- Adding one will make sure that the next image is labled 1 more than the previous
end tell
end repeat
end if
end tell
end run
-- At 'end run' is the end of the script. Please note that I've only tweaked whatléonie and Old Toad have already created. Also note that with the second script, if your file is names "My Son with fishing.jpg"... etc., name in Photos will be "My Son with fishing - 01" and not "My Son with fishing-01", the difference being the space in front and in the back of the dash. You can changed the delimiter, the space dash space, to any thing you want. Look in the second and find: & " - " &
You must keep the &'s and " marks but you can change what ever is inside the quote marks.
I hope there aren't any mistakes in here and if there is, please let me know to change it. Look at léonie and Old Toad's Scripts and Automator Workflows and you may become the next expert.
If you need further explanation on these scripts or anything Macintosh related, feel free to contact me.
I hope I help some one.
From a retired TechGuy - Ken
Mac Pro, OS X Yosemite (10.10.4)