Want to highlight a helpful answer? Upvote!

Did someone help you, or did an answer or User Tip resolve your issue? Upvote by selecting the upvote arrow. Your feedback helps others! Learn more about when to upvote >

Looks like no one’s replied in a while. To start the conversation again, simply ask a new question.

AppleScript to copy file names to Photos App

I found this script on the Apple Support board and it works very well except it copies the file names complete with the file extension. Since I am not good at script writing, I would appreciate someone suggesting how to modifiy this script to copy the file name minus the file extension.


tell application "Photos"

set medTot to count of media items

repeat with mediaIndx from 1 to medTot

tell media itemmediaIndx

if name = missing value or name = "" then

set name to filename

end if

delay 0.1

end tell

end repeat

end tell

MacBook Pro (Retina, 15-inch, Mid 2014), OS X El Capitan (10.11)

Posted on Oct 8, 2015 10:50 AM

Reply
1 reply

Oct 8, 2015 11:33 AM in response to Ralphjh

By combining parts of two scripts, I came up with the following that appears to work (at least for one file).

My next question is: do I need the delay?


tell application "Photos"

set medTot to count of media items

repeat with mediaIndx from 1 to medTo

tell media itemmediaIndx

if name = missing value or name = "" then


set myFileName to filename 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 (offsetof "." intmpFileName) -- this counts letters in the filename and then subtracts the count of the extention

set the name 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 if

delay 0.1

end tell

end repeat

end tell

AppleScript to copy file names to Photos App

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple ID.