-
Notifications
You must be signed in to change notification settings - Fork 5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Cannot delete subfolder #35
Comments
For information, |
I’ll take a look. I think I know what’s going on. The Photos AppleScript interface doesn’t provide direct access to sub folders — the code will have to traverse the folder tree and tell the parent folder to delete the sub folder. May be a little while before I can get to this as I’ve got several other projects on the front burners. |
The easiest way to implement this might be this: implement In |
Looks like I tried to tackle this once before: PhotoScript/photoscript/photoscript.applescript Lines 516 to 532 in 3d64c52
|
As I've dug into this, I think it may not be possible to fix. This appears to be due to a bug in the Photos AppleScript interface introduced in Catalina and still remaining. Apple doesn't seem interested in fixing it (though I will file a bug report with them). Sub folders can be deleted on Mojave and below but apparently not on Catalina+ One possible workaround (that's a bit hacky) could be to recreate the folder and album structure while pruning the subfolder you want to delete. This would not be efficient but is likely possible to implement. I already do something similar for removing photos from albums (this is something not allowed by Photos but PhotoScript emulates this by creating a new album with the same name then deleting the original album). |
Right. In my use-case, this issue does not annoy me that much. If too painful to fix, may be consider closing this as "won't fix". |
See this discussion on stack overflow Under Monterey, at least, deletion of subfolders in Photos is not possible via AppleScript/JXA. There appears to be a bug in delete that fails for subfolders, but not for top-level folders and not for any-level albums. tell application "Photos" tell application "Photos" tell application "Photos"
end tell The same is true for JXA. photos = Application("Photos") I did the previous testing under macOS Monterey. While testing to see if this behavior remains the same under Ventura, I noticed a possibly related behavior. While you can get id of folderToDelete as noted above, you cannot get every folder whose id is… or get every folder whose name is…. It will only return top-level folders that match, even on an id search. tell application "Photos" tell application "Photos" tell application "Photos" I suspect that this behavior is related to AppleScript’s inability to reference folders by id. There’s another bug, too. Noticing that the error is about “Can’t make folder id "xxx" of folder id "yyy" into type integer”, I tried deleting the folder by number. For example, get name of folder 5 of folder "Workshop" gave me the correct name of the example folder I’ve been trying to delete in my latest tests. But: tell application "Photos" Note that there is an interesting twist in JXA in which the result (using the syntax I’ve used) is always a list. This is probably because this is the equivalent of AppleScript’s get folders of folders of folders whose name is "Testing Folder Deletion". (Sadly, get folder of folders of folders whose name is "Testing Folder Deletion", while not a syntax error, returns a list of empty lists. It not only doesn’t return the requested folder, it also continues to return a list.) This is more obvious when getting subfolders or subalbums. A subscript is required for each level down from the application. folderToDelete = photos.folders.whose({name: "Workshop"}).folders.whose({name: "Posting Possibilities"}).folders.whose({name: "Testing Folder Deletion"}) folderToDelete.id() albumToDelete = photos.folders.whose({name: "Workshop"}).folders.whose({name: "Posting Possibilities"}).albums.whose({name: "Testing Album Deletion"}) You may wish to specify your macOS version in the question. There is some evidence online that previous to Monterey this syntax did successfully delete subfolders. It is also possible that a post-Monterey OS will fix this, as it seems very likely to be a bug. |
I'm reaching an exception deleting a subfolder:
will throw an exception on macOS 13.0 (22A380) with something like so:
Any ideas on how to circumvent this issue?
The text was updated successfully, but these errors were encountered: