PhotoFilename

Joined
Jul 13, 2022
Messages
8
Reaction score
1
Points
3
I have a 2022 MacBook running the latest Ventura OS with several thousand digitized photos in my Photo application. I wrote an Applescript to adjust some dates because some photos were obviously improperly dated for examplesummer photos with winter date. My Applescript functions accurately with the exception that I cannot seem to change the date which was on the imported photo file. I get the filename with the following code:

set PhotoFilename to filename of thisItem

However even though my Applescript log indicates that the date is changed the result is that it is not changed in actuality.

Is it possible to change the photo filename without exporting the photo from the Photo Application?
 
Joined
Jan 1, 2009
Messages
15,507
Reaction score
3,866
Points
113
Location
Winchester, VA
Your Mac's Specs
MBP 16" 2023 (M3 Pro), iPhone 15 Pro, plus ATVs, AWatch, MacMinis (multiple)
I am no expert, but your post seems contradictory, so if you could clarify, maybe someone will be able to help.

What is it you are trying to do? You mentioned changing the dates, but then asked if it was possible to change the filename. Which is it? Those are two different things.

Also, if it is the name, there is a "title" for each image, which defaults to the name of the imported file. Are you trying to change the title, or the filename?

And finally, how are you importing the images to Photos? By that I mean, in Photos/Settings, is the "Copy items to the Photos Library" checked? How that is set has a bearing on what you have asked.
 
OP
M
Joined
Jul 13, 2022
Messages
8
Reaction score
1
Points
3
My apologies for not being more clear.

I'm having no problem changing the Title. I want to change dates that are part of the filename that was imported. All of my photo files are named similar to this: 1963-11-23 ~Ken ~1.jpg. Many of these photos were scanned a long time ago and after scanning dates were added to the filename as the scanned photos did not include a proper creation date. Also, in a few cases the name portion of the filename is the wrong person... Another reason to wish to change the filename.

My Applescript can detect and display the original photo filename as part of the Photos filename. It will return something like this:

get filename of media item id "EA328B82-FF85-4CDB-B7A2-0BEEB113BF1C/L0/001"
--> "1916-01-01 ~Edgar Thompson, Bessie Thompson & Friends ~1.jpg"

And it will state that the filename is changed, but when I look at the photo info (Command-i) the name will not be changed.

The data I want to change is depicted on the second line of the image below. I am having no problems changing data on the first or third lines.


Image.jpeg
 
Joined
Jan 1, 2009
Messages
15,507
Reaction score
3,866
Points
113
Location
Winchester, VA
Your Mac's Specs
MBP 16" 2023 (M3 Pro), iPhone 15 Pro, plus ATVs, AWatch, MacMinis (multiple)
That helped. You did not answer the question about HOW you are importing images, so I'll address both options.

First, if you have the box checked for "Copy items to the Photos Library," then what happens when you import is that Photos goes to that file and imports the image into an internal database within Photos as a binary large object (BLOB) and gives it the random alphanumeric name you see in the screenshot you provided. Photoslibrary is a SQLite database, in part, and it stores the exif data in separate tables from the BLOB table, then has additional tables to track each change that is made to the original image. At that import time, the data that is on line 2 is set, as that is the source file for all the BLOB, exif, and edit data. That is the default way of importing.

But, if you don't have the box checked for copying items, then what Photos does is to note the full path name to that image and stores that data in the internal database, but NOT the image itself. Same long alphanumeric string to point to the original filename. In addition, it stores the entire pathname to the file so that it can retrieve the file the next time you open Photos. Photos depends on the user leaving the file EXACTLY in the same place if it isn't copied into the internal database, and if the user changes anything in that full path, Photos will simply say the file is missing and it cannot open it. Basically, the BLOB part isn't stored, so it has to be exactly where it was recorded at the time of the import.

In both cases, what is on line 2 is fixed at that time. It is, AFAIK, unchangeable.

It's a bit like my wife being asked for her birth certificate. It shows her maiden name. But her legal name now is different, since she took my name when we got married. So her name now is not what is on the birth certificate because she chose to change her name. But she cannot get a copy of her birth certificate with her married name because that was not her name when she was born. Can't change history. Same with that filename. That is what you imported. Can't change history. You CAN change the Title, which is the first line in your screenshot. And you then can use the Title for things like sorts, printing, whatever. Just like my wife has a passport with her new name, and a driver's license, etc. But the name of the file you imported, on the second line, is the name you imported. It was the "birth name" of the image. You can change the name when you EXPORT the image back to a straight file, but you cannot change what you imported. Again, history.

Ok, back to the two cases. In the first case, if you really, really, really want change the names, you will have to go back to the original import process and change the name of the file BEFORE you import them. Doing that renaming/reimporting will mean that you will have a lot of work.

If the original files are no longer available, you will have to export all of them from Photos, edit the filenames using Finder (or Terminal, or AppleScript, it doesn't matter) to whatever you want them to be, then create a new photos library and import them all new. At that point all edits you have made to the images will be lost, because the edits are also stored in Photos in the database and reapplied each time you open the image. And before you ask, no, you cannot export, rename, import to the SAME Photos database and have Photos reapply the edits for you. Can't change history that way. Note that Photos will allow you to save the ORIGINAL file because it knows what that file is, and it has kept it in the database, or you can export the changed file but then Photos won't have the record of edits on the new imported file because the new imported file hasn't been edited by Photos. And you can make the filename of the new image be the TITLE instead of the Filename in the export dialog, so you could make the title changes in Photos, export the images using Titles for filenames, then import them into a new photos library and the data on line 2 will now be what the Title was in the original Photos database. But, the edits are gone. Can't get around that. It's much like the relationship of my wife's birth certificate and wedding license. One shows what she was at birth, the other shows the change from old to new name. If she could convince the state to make the change on the birth certificate to show her married name, the marriage license would be invalid because it shows her birth name. Can't change history. Given how Photos operates, if the original filename changes, the links to the BLOB, or the external file that wasn't copied in, is broken.

If the original files are available, and you want to do this, you don't have to export from Photos, you can just change the actual filenames of the files and import them into a new Photos library. Works out the same, edits are lost, etc.

In either case, once you have the files imported with the new names and you know everything is OK, you can delete the OLD Photos library to make space available again from that drive.

If, on the other hand, the box is NOT checked to copy in the images as BLOBs, then what Photos does is to reconstruct the exact path to the original file, but it then stores the edits to that original in the Photos database and reapplies them each time you open the image. Note, the original file is NOT changed by the edits, it is still the original file. But the edits to that file are stored and applied, and if you EXPORT that edited image you get a new file with the edits applied and the history lost for that file. (In this case there is no point in exporting the original file, it was never actually imported.) And, critically, if you change the location OR NAME of that file using Finder, Terminal, AppleScript or anything else, then Photos will not be able to find that image file because the path to the file will be pointing to what was imported, not what you renamed the file. Again, you will have to re-import the renamed file, and the old edits to the old name file will be lost.

Bottom line: AFAIK, Line 2 cannot be changed once created. Title (first line) can. Date (third line) can. But not line 2. It's the "maiden" name at birth and is fixed in history. I don't know why AppleScript is reporting the name is changed when it is not. Might be a bug in AppleScript, or your script, but the filename is unchangeable.

I'm 99.9% sure of what I have described. I don't know all of the internals of HOW Photos tracks everything, the library is an SQLite database with all kinds of tables for edits, files, blobs, thumbnails, etc., and I don't have the schema for the database and just don't want to spend the time or effort to try to sort it out. So, someone may come along and have a magic trick that will do the transformation you want, but I seriously doubt it.

My vote would be to leave Line 2 alone, too much work to export, reimport, re-edit. Just live with it.

Hope that helps. I know it isn't what you wanted to hear.
 
OP
M
Joined
Jul 13, 2022
Messages
8
Reaction score
1
Points
3
I didn't want to hear this???... That is an extremely inaccurate statement.

While your explanation does not offer an easy solution for my situation, it is IMO a very valuable explanation of how the Photos Application functions.

I thank you ever so much for this detailed explanation and the time it took you to create it.

Thanx... You are appreciated!
 
Joined
Jan 1, 2009
Messages
15,507
Reaction score
3,866
Points
113
Location
Winchester, VA
Your Mac's Specs
MBP 16" 2023 (M3 Pro), iPhone 15 Pro, plus ATVs, AWatch, MacMinis (multiple)
I didn't want to hear this???... That is an extremely inaccurate statement.
Most people don't want to hear they can'd do what they want to do. Thanks for the nice comments.
 

Shop Amazon


Shop for your Apple, Mac, iPhone and other computer products on Amazon.
We are a participant in the Amazon Services LLC Associates Program, an affiliate program designed to provide a means for us to earn fees by linking to Amazon and affiliated sites.
Top