Sunday, November 29, 2020

#1 2015-05-30 06:59:35 am

poleary2000
Member
Registered: 2011-12-15
Posts: 4

Photos - Remove Photos from Album

Hi there,

I know not much is being done with Photos yet, but I want to write Apple script to remove all photos from a specific Album.  Example Album name is Test.

Remove all photos from "Test"

Possible?

Offline

 

#2 2015-06-01 06:27:16 pm

kel1
Member
Registered: 2013-01-11
Posts: 2188

Re: Photos - Remove Photos from Album

Hi,

Interesting question. They don't seem to have a delete mechanism. Hmm.

Edited: or even a move (like to the trash). smile

Later,
kel

Last edited by kel1 (2015-06-01 06:29:24 pm)


Os 10.10.3
Mbp

Offline

 

#3 2015-06-01 06:35:50 pm

kel1
Member
Registered: 2013-01-11
Posts: 2188

Re: Photos - Remove Photos from Album

I got an idea. What if you create a new album with the same name and replace the other album. Would that work?


Os 10.10.3
Mbp

Offline

 

#4 2015-06-01 06:40:47 pm

kel1
Member
Registered: 2013-01-11
Posts: 2188

Re: Photos - Remove Photos from Album

Here's the one:

remove v : Remove the given object from its container.
remove specifier : the object for the command
[from any] : The container from which to remove the object.


That's probably it!

gl,
kel


Os 10.10.3
Mbp

Offline

 

#5 2015-06-01 06:43:08 pm

kel1
Member
Registered: 2013-01-11
Posts: 2188

Re: Photos - Remove Photos from Album

So, it would go something like this:
remove every item from (a reference to the album).


Os 10.10.3
Mbp

Offline

 

#6 2015-06-01 06:47:33 pm

kel1
Member
Registered: 2013-01-11
Posts: 2188

Re: Photos - Remove Photos from Album

In the case you're wondering how I found that was to look in the dictionary of Photos.

gl and happy scripting,
kel


Os 10.10.3
Mbp

Offline

 

#7 2015-06-01 07:01:10 pm

kel1
Member
Registered: 2013-01-11
Posts: 2188

Re: Photos - Remove Photos from Album

Tell me if that was it. Otherwise, there might be a little more to it.

Edited: you never know.

Edited: the reason why I say this is I don't have much time. I would have to create a new album and test on that. But, I'm washing clothes! big_smile  and hopefully can rest after that.

gl,
kel

Last edited by kel1 (2015-06-01 07:04:56 pm)


Os 10.10.3
Mbp

Offline

 

#8 2015-06-03 05:01:53 pm

kel1
Member
Registered: 2013-01-11
Posts: 2188

Re: Photos - Remove Photos from Album

Hi Poleary,

Did you get it to work?

Now I have some time and was thinking about trying out the 'remove' with the filter reference form. The part I didn't like was removing every photo from an album. So, I have to crate a whole new small album and didn't have time.

I'll show you a good example if I can think of one.

Edited: btw, not sure but it read like you knew about AppleScript so I was very vague.

Later,
kel

Last edited by kel1 (2015-06-03 05:03:15 pm)


Os 10.10.3
Mbp

Offline

 

#9 2015-06-03 05:22:29 pm

kel1
Member
Registered: 2013-01-11
Posts: 2188

Re: Photos - Remove Photos from Album

Ok, what I was thinking is that say you have an album selected. So, what you want to do is remove every photo from that album. The selection doesn't seem to cover albums. so, you need to somehow get your script to select an album.

I got it! You choose the album from the list or another way way might be to select a photo from an album and from there get the album. I kind of like the idea of selecting an album to delete items. Sounds good to me.

Edited: Ooo, It's a little bit trickey.:D Nice puzzle.

Later,
kel

Last edited by kel1 (2015-06-03 05:26:48 pm)


Os 10.10.3
Mbp

Offline

 

#10 2015-06-03 05:36:32 pm

kel1
Member
Registered: 2013-01-11
Posts: 2188

Re: Photos - Remove Photos from Album

I'm starting to think that the best way to do this is to go back to the original idea of deleting the album and creating a new album. Interesting though. What if I just wanted to delete every photo but the last one.


Os 10.10.3
Mbp

Offline

 

#11 2015-06-03 05:43:49 pm

kel1
Member
Registered: 2013-01-11
Posts: 2188

Re: Photos - Remove Photos from Album

Darn, I can't find the remove command. It must have been from iPhoto.:) Ok, damn it. Gotta get serious here..:D


Os 10.10.3
Mbp

Offline

 

#12 2015-06-03 05:54:09 pm

kel1
Member
Registered: 2013-01-11
Posts: 2188

Re: Photos - Remove Photos from Album

Ok, think I found the secret. This reminds me of Mail when ti first came out. It seems the programmers don't know about AppleScript very much.


Os 10.10.3
Mbp

Offline

 

#13 2015-06-03 06:03:52 pm

kel1
Member
Registered: 2013-01-11
Posts: 2188

Re: Photos - Remove Photos from Album

I got it! Why the hell did they use container instead of album? Crazy man.


Os 10.10.3
Mbp

Offline

 

#14 2015-06-03 06:14:50 pm

kel1
Member
Registered: 2013-01-11
Posts: 2188

Re: Photos - Remove Photos from Album

Darn, I remember now. Had to delete it from the database. Darn! That's why I was asking how to delete items from the database. I think. Yeah, I think that was it. I remember something about sqlite or something like that.


Os 10.10.3
Mbp

Offline

 

#15 2015-06-03 06:17:06 pm

kel1
Member
Registered: 2013-01-11
Posts: 2188

Re: Photos - Remove Photos from Album

The way Apple has it now, you can't even hack your own computer!


Os 10.10.3
Mbp

Offline

 

#16 2015-06-03 08:04:38 pm

kel1
Member
Registered: 2013-01-11
Posts: 2188

Re: Photos - Remove Photos from Album

Darn, I think you have to resort to uielement scripting to get rid of the photos.:( It's too bad because all you would actually need to do is delete it from the database, if.

gl,
kel


Os 10.10.3
Mbp

Offline

 

#17 2015-06-03 08:20:09 pm

kel1
Member
Registered: 2013-01-11
Posts: 2188

Re: Photos - Remove Photos from Album

In the olden days you might find that database and make changes, but now days you might just as well wait and perhaps send in some feedback to Apple.

gl,
kel


Os 10.10.3
Mbp

Offline

 

#18 2015-06-03 08:27:07 pm

kel1
Member
Registered: 2013-01-11
Posts: 2188

Re: Photos - Remove Photos from Album

Here's as far as I got and then you need to search trough the database I think:

Applescript:

tell application "Photos"
   set the_album to first container whose name is "TestAlbum1"
   every media item of the_album
end tell

From there you need to find the database and modify it. And then you don;t know if that will even work I think.

gl,
kel


Os 10.10.3
Mbp

Offline

 

#19 2015-06-10 07:25:10 am

poleary2000
Member
Registered: 2011-12-15
Posts: 4

Re: Photos - Remove Photos from Album

Hi there,

THANK YOU so much for your help.  I wasn't able to test it yet.  Prior to your help, I got fed up with the speed of Photos on OS X.  It was choking on my 60k picture library.  I literally couldn't do anything without it giving me the beachball of death. 

I will definitely save this and use / try it out once I test it again under OS X El Capitain. 

Thanks again, and sorry for the delay responding!

Offline

 

#20 2015-06-11 04:03:12 pm

kel1
Member
Registered: 2013-01-11
Posts: 2188

Re: Photos - Remove Photos from Album

Hi poleary,

Actually, there is no solution as I remember. Maybe in the future there might be one.

gl,
kel


Os 10.10.3
Mbp

Offline

 

#21 2015-08-02 10:38:51 am

scottfwalter
Member
Registered: 2014-07-30
Posts: 20

Re: Photos - Remove Photos from Album

kel1 wrote:

So, it would go something like this:
remove every item from (a reference to the album).


I'm trying to remove all the photos from an album but I can't seem to find "remove" in the dictionary.  I see "delete" but that is only for albums and folders.   

I tried:
[code]       
set target_album to album named target_album_name of container target_folder_name
repeat with photo in media items in target_album
  remove photo
end repeat[/code]
Any thoughts?  For now I am deleting the album and recreated.  However i would prefer just to remove the media items.

Offline

 

#22 2019-08-04 08:08:17 am

KniazidisR
Member
From:: Greece
Registered: 2019-03-03
Posts: 1444

Re: Photos - Remove Photos from Album

Applescript:


tell application "Photos"
   activate
   set thePhotos to media item of album "Alexandra"
   
   repeat with thePhoto in thePhotos
       spotlight thePhoto
       delay 1
       tell application "System Events"
           tell application process "Photos"
               click menu bar item "Image" of menu bar 1
               try
                   click menu item "Delete 1 Photo" of menu 1 of menu bar item "Image" of menu bar 1
               on error
                   click menu item "Remove 1 Photo from album" of menu 1 of menu bar item "Image" of menu bar 1
               end try
               repeat while (sheet 1 of window 1 exists)
                   delay 0.1
               end repeat
           end tell
       end tell
   end repeat
   
end tell

NOTE: you can filter deleted photos with some criteria.

The following script automatically deletes all photos whose name contains "1", without confirmation:

Applescript:


tell application "Photos"
   activate
   set thePhotos to media item of album "Alexandra"
   
   repeat with thePhoto in thePhotos
       if name of thePhoto contains "1" then
           
           spotlight thePhoto
           delay 1
           tell application "System Events"
               tell application process "Photos"
                   click menu bar item "Image" of menu bar 1
                   try
                       click menu item "Delete 1 Photo" of menu 1 of menu bar item "Image" of menu bar 1
                   on error
                       click menu item "Remove 1 Photo from album" of menu 1 of menu bar item "Image" of menu bar 1
                   end try
               end tell
               delay 0.5
               keystroke return
           end tell
           
       end if
       
   end repeat
end tell

Last edited by KniazidisR (2019-08-04 08:55:00 am)


Model: MacBook Pro
OS X: Catalina 10.15.4
Web Browser: Safari 13.1
Ram: 4 GB

Offline

 

#23 2019-08-04 09:14:47 am

KniazidisR
Member
From:: Greece
Registered: 2019-03-03
Posts: 1444

Re: Photos - Remove Photos from Album

The Last NOTE: The deleted photos goes to the folder "Recently Deleted". This is a trash of Photos app. To permanently empty this trash you should add to end of the scripts above that:

Applescript:


tell application "System Events" to tell application process "Photos"
   click static text 1 of UI element 1 of row 8 of outline 1 of scroll area 1 of splitter group 1 of window 1
   repeat until (window 1 exists)
       delay 0.1
   end repeat
   click UI element "Delete All" of group 1 of splitter group 1 of window 1
   delay 0.5
   click UI element "OK" of sheet 1 of window 1
end tell

Last edited by KniazidisR (2019-08-04 09:15:28 am)


Model: MacBook Pro
OS X: Catalina 10.15.4
Web Browser: Safari 13.1
Ram: 4 GB

Offline

 

#24 2020-09-27 02:56:12 am

KniazidisR
Member
From:: Greece
Registered: 2019-03-03
Posts: 1444

Re: Photos - Remove Photos from Album

poleary2000 wrote:

I want to write Apple script to remove all photos from a specific Album.

kel1 wrote:

Actually, there is no solution as I remember. Maybe in the future there might be one.


So. Photos.app doesn't have a delete command to delete all photos from some album. Earlier I suggested a GUI-scriping solution to this problem. But now, after thinking a little with my brains, I thought it would be better to do it like this, without any GUI-scripting:

Applescript:


set theAlbumName to "Untitled Album" -- note: on my Mac its container is folder "Robert"

tell application "Photos"
   set theAlbum to album theAlbumName of folder "Robert"
   delete theAlbum
   make new album named theAlbumName at folder "Robert"
end tell

Last edited by KniazidisR (2020-09-27 03:13:15 am)


Model: MacBook Pro
OS X: Catalina 10.15.4
Web Browser: Safari 13.1
Ram: 4 GB


Filed under: photos

Offline

 

#25 2020-09-28 10:33:28 pm

KniazidisR
Member
From:: Greece
Registered: 2019-03-03
Posts: 1444

Re: Photos - Remove Photos from Album

I have already shown above how 1) how to delete specific photos from an album using GUI scripting, 2) clear the album from all photos without GUI scripting.

Now, I would like to show 3) how to delete from album a specific selected photo without GUI scripting. That is, the same as 1), but without GUI scripting:

Applescript:


set theAlbumName to "Untitled Album" -- note: on my Mac its container is folder "Robert"
set tempAlbumName to theAlbumName & "_Temp"

tell application "Photos"
   activate
   -- create reference to original album
   set theAlbum to album theAlbumName of folder "Robert"
   -- remember the ID of first selected photo, to use later
   set theID to id of item 1 of (get selection)
   -- get list of rest media items
   tell theAlbum to set others to every media item whose id is not theID
   -- make temporary album, create reference, add "other" media items
   make new album named tempAlbumName at folder "Robert"
   set tempAlbum to album tempAlbumName of folder "Robert"
   add others as list to tempAlbum -- as list is required here
   -- delete original album
   delete theAlbum
   -- restore name to original album's name
   set name of tempAlbum to theAlbumName
end tell

NOTE: The given script implies the indication of the full path to the album by the user. With recursive handler it is possible finding the full path to album of selected message automatically. I'll figure out how to do it. Help from other users is also greatly appreciated. There is only one condition - no GUI scripting.

Last edited by KniazidisR (2020-09-28 11:02:14 pm)


Model: MacBook Pro
OS X: Catalina 10.15.4
Web Browser: Safari 13.1
Ram: 4 GB

Offline

 

Board footer

Powered by FluxBB

RSS (new topics) RSS (active topics)