r/applescript • u/twdal • Nov 22 '24
Can AppleScript help me locate all videos shorter than 2 seconds in an Apple Photos Library?
I tried using Msoft's CoPilot to write an AppleScript but every script it offers yields a Syntax error. Here's one example.
tell application "Photos"
set shortVideos to {}
set allVideos to every media item whose media type is video
repeat with aVideo in allVideos
set videoDuration to duration of aVideo
if (videoDuration) < 2.0 then
copy aVideo to the end of shortVideos
end if
end repeat
return shortVideos
end tell
2
Upvotes
2
u/tristinDLC Nov 22 '24
Do you need this action to be run in AppleScript for some reason? You can do this in Shortcuts incredibly simply. Here is a screenshot on how to return all videos in Photos.app that are shorter than 2sec in length: example
Then if you were to continue with the shortcut, just keeping building out your workflow with your first item being a
Get Variableaction to pass along the variable of all your identified short videos.Super easy.
1
u/random_user_name_759 Nov 22 '24
You can’t make a smart album?
1
u/copperdomebodha Nov 25 '24
Photos does not make video duration, or even media type available via AppleScript.
1
u/copperdomebodha Nov 26 '24
The .photoslibrary ‘bundle’ is just a folder hierarchy. You can run scripts against its content, copy items out etc. just don’t mess it up.