Struggling to build a shortcut for media files management

Hello!


I am struggling to build a Shortcut to rename a bunch of media files (pictures and videos taken with my iPhone). I would like to add a timestamp and the city where the picture or video was taken. My difficulties as of today are:


  • how can I test the content type of a file (video, picture...)? Not just the extension, since they can be numerous, but the overall filetype...
  • how can I retrieve the geolocation data of a video? No problem for pictures, but for a video I don't find a way... (I precise that my videos are geolocated, the info is available for example with the Quicktime inspector).
  • Finally, is there a way to avoid the security check popup linked to renaming the files? I have to manually allow access to each and every sub-folder, which is painful and kind of opposite to the automatisation philosophy.


Many thanks for your help!



MacBook Air 13″, macOS 12.6

Posted on Jan 22, 2023 6:21 AM

Reply

Similar questions

5 replies

Jan 22, 2023 9:13 AM in response to Thomas from Bordeaux

If this is going to incrementally evolve into your own photo and video management database, seriously consider reviewing and starting out using one of the available photo and video databases.


Or if you prefer to learn more about image and video metadata including about Exif metadata, I’d consider using better tooling than Shortcuts.


One tool for a more complete photography database would be Filemaker Pro, and that seems to have support for Exif and other metadata available. Probably need another tool to set the Exif data, as I don’t see a matching set function. But Filemaker Pro deals with a whole lot of the rest of a photo-management application.


If you were to use a shell script such as zsh shell built into macOS as the foundation for your photo management platform and tooling, get exiftools, and load the metadata you want into the image, if it isn’t already loaded into the image or video by the camera. The exiftools package can read and write many formats, including the metadata from MP4 video files.


To test the file contents, use the file magic tool available at the command line. man file The built-in file tool works reasonably for this case. (If you should evolve this and be accepting files from untrusted sources, I’d likely switch to the OpenBSD file magic tool, as that’s more robust against shenanigans.)


Filenames are probably best kept as UUIDs / GUIDs or other such “generated” unique names to avoid the seemingly inevitable naming collisions when some sequence number or another get restarted, or some second or third or forth device produces conflicting names, as tends to happen with apps and cameras and apps that use sequence numbers.


I’ve previously posted a zsh bulk file rename tool here: short cut date as file name - Apple Community


Various folks that have previously traveled this path can be found searching for exiftool references around here and else-network, too. It’s a tool that’s widely used for these tasks.


Might want to ask Apple to improve this area, both renaming, and for enhancing Shortcuts with direct Exif metadata and related access. (Right now, it’s probably easier to use the command shell directly, or to use Shortcuts to access the shell and exiftools or such.)


Two previous threads you’ll want to skim:

How to remove metadata in a an .mp4 file … - Apple Community (exiftools examples)

Using script: rename a file with "text_MM… - Apple Community (Swift code, and Automator calling exiftools)




Jan 22, 2023 10:18 AM in response to Thomas from Bordeaux

I would use zsh here, not Shortcuts.


Shortcuts is useful for simple automation and app scripting stuff, and I have a bunch of that around, but I usually seem to hit some wall or another when using it for more complex app development. Exif metadata access is one such area, workarounds aside.


On Mac particularly, better and more flexible tools are built in, and other tools are readily available. zsh, Swift (particularly when used with Playgrounds for development), Python, etc.


And if I need a UI from a zsh or older bash shell script, a call to osascript works.


The future for Automator and AppleScript/JavaScript is unclear. Shortcuts has been getting most of the coverage at Apple. Automator hasn’t seen much Apple coverage since the JavaScript announcement. (And I do hope all of these continue to receive updates and enhancements, but recent Apple focus has been on Shortcuts, and particularly Swift, and replacing bash with zsh.)

Jan 22, 2023 9:30 AM in response to MrHoffman

PS1: Storing and usint UTC time works (way) better than local time (you’ll learn why, if you don’t).


PS2: Using YYYYMMDD works (sorts) (way) better than other formats, if you do use that as the filename.


PS3: If you’re going to have lots of photos and videos, don’t stuff them all un one ginormous directory. That gets slow, slower, glacial.


PS4: User VikingOSX had a fairly discussion with somebody here over the past month or so here in this community, about using Shortcuts for similar tasks.


Jan 22, 2023 9:59 AM in response to MrHoffman

Thank you for this elaborate answer!

Just to clarify, I don't want to develop my own management database (I am aware of my limits). I just need the timestamp and location in the filename to help me sort pictures out when I print them on paper (the filename appears on the back).


I used to develop small stuff with Applescripts, but I find it more and more difficult these days (I am wondering if Apple has not intended to drop Applescript, which would be a pity). As such, I wanted to try this new tool, and here I am, struggling.


From what I read of your response, Shortcuts is not the tool for this task?

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.

Struggling to build a shortcut for media files management

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