Where are photo file names?

I've "titled" many, many photos in iPhoto by changing the filename (e.g. "DSC_2254" --> "On vacation in Hawaii"), but there appears to be no option in Photos to show the filename. So none of my "titles" appear. Am I missing something?

iMac (Retina 5K, 27-inch, Late 2014), OS X Yosemite (10.10.3)

Posted on Apr 9, 2015 7:56 AM

Reply
Question marked as Top-ranking reply

Posted on Feb 8, 2018 4:28 AM

If you open your Photos Library in Power Photos as a second browser, you can seethe metadata as column in a nice list view, or you can show the filenames as a subtitle below the thumbnails.

Even the free trial version can do this.

User uploaded file

As an added bonus, the grid view can show the thumbnails on a dark background:

User uploaded file

For a very large library PowerPhotos needs a long time to launch, so I simply keep it open at all the time.

282 replies

May 3, 2015 7:15 PM in response to léonie

Here is an improved version that allows specific extensions to be excluded or included in the titles.



-- Photos | Filename to Title | V1.2


-- Images with no title will have the filename used as the title

-- Use values below to exclide or include specfic file extensions from the generated title

-- Existing titles will be modified to add or remove any extension from the title as required


set exclude to ".jpeg.jpg.mov.png.tif.tiff" -- Extensions to exclude from the image titles

set include to ".cr2" -- Extensions to include in the image titles


tell application "Photos"

activate

set updated to 0

set info to "Photos | Filename to Title"

set images to (get selection)

if images is {} then

display dialog "Please select items in Photos before calling this script." with title info buttons {"OK"} giving up after 5

else

repeat with image in images

set fullName to filename of image

set title to the name of image

if not (exists (title)) or title = "" then

set title to fullName

set current to ""

else

set current to title

end if

set pos to offset of "." in ((reverse of characters of title) as string)

set prefix to characters 1 thru (-1 - pos) of title as string

if pos > 0 then

set postfix to characters -pos thru -1 of title as string

else

set postfix to ""

end if

set pos to offset of "." in ((reverse of characters of fullName) as string)

set ext to characters -pos thru -1 of fullName as string

if (offset of postfix in exclude) > 0 then

set newTitle to prefix

else

set newTitle to prefix & postfix

end if

if (offset of ext in include) > 0 and not ext = postfix then

set newTitle to newTitle & ext-- Or could test here and add something like " | RAW" for raw formats

end if

if not current = newTitle then

set the name of image to newTitle

set updated to updated + 1

end if

end repeat

if updated = 1 then

set message to " item was updated."

else

set message to " items were updated."

end if

if updated = 0 then

set message to "No" & message

else

set message to (updated as string) & message

end if

display dialogmessagewith titleinfobuttons {"OK"}

end if

end tell


It could be further enhanced by adding specific text to the title instead of the extension, e,g, add say " | RAW" instead of ".cr2", or various other automatic substitutions could be made.


tt2

May 3, 2015 9:05 PM in response to turingtest2

I noticed something I don't understand occurring in both the original & improved version of your script:


When I run it in Script Editor with the log window set to show replies, every time the script calls 'offsetof' inside the tell application "Photos" block, the log shows that statement returns error number -10004. That is immediately followed by an end tell, a tell current application block with a duplicate of the 'offsetof' statement that returns the correct offset value, & then another tell application "Photos" statement to resume the tell Photos block. For example:


tell application "Photos"


offset of ".jpg" in ".cr2"


--> error number -10004

end tell

tell current application


offset of ".JPG" in ".cr2"


--> 0

end tell

tell application "Photos"


This doesn't prevent the script from running -- it is like Photos can't hand off the offset string command to StandardAdditions but Script Editor (or something) is smart enough to handle the error & do that internally. FWIW, the error is eliminated by enclosing each of the 'offsetof' commands inside the tell application "Photos" block in a tell me to statement to make that explicit.


Anybody else seeing this?

May 4, 2015 2:53 AM in response to R C-R

OK. That is somewhat unintuitive. The offset clauses are all grouped together in an area which doesn't need to communicate with Photos so a single tell me ... end tell construct is enough to avoid all of those errors. Better yet a use scripting additions inserted near the top of the script does the same thing, so now we have:




-- Photos | Filename to Title | V1.3


-- Images with no title will have the filename used as the title

-- Use values below to exclude or include specfic file extensions from the generated title

-- Existing titles will be modified to add or remove any extension from the title as required


set exclude to ".jpeg.jpg.mov.png.tif.tiff" -- Extensions to exclude from the image titles

set include to ".cr2" -- Extensions to include in the image titles

use scripting additions-- Prevents errors triggered by offset clause

tell application "Photos"

activate

set updated to 0

set info to "Photos | Filename to Title"

set images to (get selection)

if images is {} then

display dialog "Please select items in Photos before calling this script." with title info buttons {"OK"} giving up after 5

else

repeat with image in images

set fullName to filename of image

set title to the name of image

if not (exists (title)) or title = "" then

set title to fullName

set current to ""

else

set current to title

end if

set pos to offset of "." in ((reverse of characters of title) as string)

set prefix to characters 1 thru (-1 - pos) of title as string

if pos > 0 then

set postfix to characters -pos thru -1 of title as string

else

set postfix to ""

end if

set pos to offset of "." in ((reverse of characters of fullName) as string)

set ext to characters -pos thru -1 of fullName as string

if (offset of postfix in exclude) > 0 then

set newTitle to prefix

else

set newTitle to prefix & postfix

end if

if (offset of ext in include) > 0 and not ext = postfix then

set newTitle to newTitle & ext-- Or could test here and add something like " | RAW" for raw formats

end if

if not current = newTitle then

set the name of image to newTitle

set updated to updated + 1

end if

end repeat

if updated = 1 then

set message to " item was updated."

else

set message to " items were updated."

end if

if updated = 0 then

set message to "No" & message

else

set message to (updated as string) & message

end if

display dialogmessagewith titleinfobuttons {"OK"}

end if

end tell




And what is interesting is that the log looks the same whichever way you do it.




tell application "Photos"

activate

get selection

--> {media item id "aXv5SiYeRyyCI%azWIuDnA"}

get filename of media item id "aXv5SiYeRyyCI%azWIuDnA"

--> "IMG_0735.png"

get name of media item id "aXv5SiYeRyyCI%azWIuDnA"

--> "IMG_0735.cr2"

exists "IMG_0735.cr2"

--> true

end tell

tell current application

offset of "." in "2rc.5370_GMI"

--> 4

offset of "." in "gnp.5370_GMI"

--> 4

offset of ".cr2" in ".jpeg.jpg.mov.png.tif.tiff"

--> 0

offset of ".png" in ".cr2"

--> 0

end tell

tell application "Photos"

display dialog "No items were updated." with title "Photos | Filename to Title" buttons {"OK"}

--> {button returned:"OK"}

end tell

Result:

{button returned:"OK"}



I can see use scripting additions becoming a standard declaration in my future scripts. 😉


Thanks for introducing me to the delights of the replies log.


tt2

May 4, 2015 5:22 AM in response to léonie

léonie wrote:

Do you have custom scripting additions installed?

I havenever tried to use them in an Automator workflow, only in standalone scripts.

Quite possibly, I'm completely wrong about this, but it seems like the weird "silent" tell current application block insertions shown in the Replies log are relying on the StandardAdditions.osax scripting addition to evaluate the offset command, which (I assume) is still part of everyone's OS X installation (in /System/Library/ScriptingAdditions), like it is in mine.


However, I just noticed that even Finder generates the same errors & current application behavior, so this isn't just something related to Photos. For example, this script:

tell application "Finder"

offset of "this text" in "some string of text including this text."

endtell

generates this in the Replies log:

tell application "Finder"

offset of "this text" in "some string of text including this text."

--> error number -10004

end tell

tell current application

offset of "this text" in "some string of text including this text."

--> 31

end tell

Result:

31

May 4, 2015 6:15 AM in response to R C-R

A little experimentation shows that the use scripting additions clause causes a problem if it is inside the on run {input, parameters} ... end run construct that was in léonie's automator example. If I put it outside, or simply dispense with that block altogether, then it seems to be OK. So what do I lose by leaving that out, or perhaps a better question is in what circumstances would it be useful?


tt2

May 4, 2015 6:33 AM in response to turingtest2

turingtest2 wrote:

So what do I lose by leaving that out, or perhaps a better question is in what circumstances would it be useful?

Good questions that I have no answers for, other than that possibly the "AppleScript must use a less efficient dispatching scheme, so explicitly declaring them is recommended" verbiage in Apple's reference might mean scripts that include use statements run faster or use less resources or something.

May 4, 2015 6:46 AM in response to turingtest2

The "use scripting additions" clause is only necessary, if you are using more than one "Use" clause for scripting additions.

But since you are only using the "StandardAdditions.sdef" for the dialogs, it should not be necessary.


See these Help pages:

http://macosxautomation.com/mavericks/usestatement/01.html

http://www.mactech.com/articles/mactech/Vol.10/10.01/ExtendApplescript/index.htm l

May 4, 2015 9:23 AM in response to turingtest2

turingtest2:


I modified the script from your last post (which doesn't show up for me here - was it pulled for some reason?) to add several other extensions:

set

set exclude to ".jpeg.jpg.mov.png.tif.tiff.psd.nef.dng.cr2" -- Extensions to exclude from the image titles

set include to ".cr2" -- Extensions to include in the image titles

I've tested it with psd, nef, dng and cr2 files successfully. It didn't work with the .cr2 files unless I added it to the first line.

May 4, 2015 11:13 AM in response to turingtest2

Do you mean you needed to add .cr2 into the exclusion list before it would be force added by the inclusion list? That shouldn't be necessary

I closed Photos, edited the script to remove .cr2 from the full list, opened Photos and tried again. All files were renamed except the .cr2 file. I checked the original file and it's extension was .CR2, in caps. That must be why.


Added another line to the script

set include to ".CR2" -- Extensions to include in the image titles

and that didn't work.


So I changed the two lines to:

set exclude to ".jpeg.jpg.mov.png.tif.tiff.psd.nef.dng.CR2" -- Extensions to exclude from the image titles

set include to ".cr2" -- Extensions to include in the image titles

I had added a lower case .cr2 file to the batch and all were correctly renamed with the script change above.


I'm not a scriptor so this was just by trial and error.


By the way I still can't see the post with V1.3. For some reason it remains invisible to me.


NOTE: you should add your script to the others in the Photos User Tips section.

May 4, 2015 2:28 PM in response to turingtest2

turingtest2 wrote:

It seems that in principle display dialog should be causing the same kind of error, or at least it would have done in days gone by. I can't see why that can be handled without triggering an error but offset does.

Nor can I. I'm still puzzling over the OS X Automation article statement that "scripting addition commands are not available by default." That implies that a use scripting additions statement should always be necessary to use anything in the StandardAdditions suites, including display dialog, offset, delay, & many other commonly used commands. But I know that most do not; in fact so far it is only offset that I have noticed the strange error & automatically generated tell current application behavior with.


I get it that if the script has any other use statement (like use application "whatever" or use script "whatever") then you have to include a use scripting additions one, but that isn't true for your script or any of the ones I have experimented with.


Something else that is puzzling is the upper/lower case issue that OT mentioned. I assumed I would have to add "JPG" to the list for your script to properly handle some of my Photos files with that capitalized version of the extension, but it did not seem to be necessary, nor was there any difference with or without it in the exclude list. This sort of jibes with something I read about the considering & ignoring statements in Apple's docs (that ignoring case is the default behavior) but I'm not sure why it (apparently?) makes a difference for OT's files & not mine.


Speaking of which, I'm not sure the whole offset into a string method is a bulletproof way of uniquely identifying extensions. I haven't checks (nor do I know if it would ever come up in this context) but consider what might happen if the extension was something like .cr2 & there also was a .cr2a one. The first does have a non-zero offset into the second, so could that be problematic in some scenarios?


In the past, & for a different use, I have handled this by using a list of strings instead of a single string with all of them in it -- like set exclude_list to {"text 1", "text", "text 2", "whatever"} -- which I then test against with a simple "is in" statement. That probably is not necessary in this use ... but it does avoid the pesky offset command. 😝

May 4, 2015 3:12 PM in response to R C-R

I'd read up on case sensitivity too and both theory and practice (in my case) said I didn't need to worry about it, but perhaps it would be better if I made it explicit. As for substring searches I'd thought about it, but I've assumed until I know otherwise that there isn't a potential for a clash within the relatively limited set of valid image entensions. I've yet to explore more deeply but in my vbScripts I sometimes wrap the values with vertical bars, e.g. "|.jpg|.mov|.png|.tif|" and then add them to the search term. VBS doesn't have anything that looks as efficient if element is in list, on the other hand I've found that AppleScript doesn't seem to like some nested clauses which I would normally use to avoid having to declare variables to hold intermediate results. I shall find out what works and what doesn't. 🙂


tt2

May 4, 2015 4:16 PM in response to turingtest2

turingtest2 wrote:

VBS doesn't have anything that looks as efficient if element is in list, on the other hand I've found that AppleScript doesn't seem to like some nested clauses which I would normally use to avoid having to declare variables to hold intermediate results.

Handling lists seems to me to be one of Applescript's most powerful features, but I have admit I often find them hard to work with, particularly when lists of lists are involved.

May 4, 2015 4:24 PM in response to Old Toad

Old Toad wrote:

I noticed that the second line I've been working with is "Set to include" which keeps .cr2 in the title. I removed that line, keeping .cr2 in the line above, and got the following error message.

I assume you mean "set include to" & not "set to include" but since the include variable is used later in the script (in the if (offsetofextininclude) > 0 andnotext = postfixthen statement) the script will error out with that message whenever it tries to execute it.


That much I understand. The rest of it, not so much. 😟

This thread has been closed by the system or the community team. You may vote for any posts you find helpful, or search the Community for additional answers.

Where are photo file names?

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