Rename File Failing

Get help. Get answers. Let others lend you a hand.

Moderator: Mr_Noodle

Rename File Failing Fri Feb 25, 2022 9:40 am • by brijazz
I'm running an AppleScript that finds a video's resolution via ffprobe and appends it to the file name. No problem with ffprobe or building the new file name, but adding the extension back onto the file name is failing. Any advice?

Code: Select all
tell application "Finder"
   
   -- get filename and extension
   set theEpisodeName to name of theFile
   set theExtension to name extension of theFile
   
   --get the filename without extension
   set theEpisodeName to text 1 thru ((theEpisodeName's length) - (offset of "." in (the reverse of every character of theEpisodeName) as text)) of theEpisodeName
   
   -- get video resolution
   set theEpisode to quoted form of POSIX path of theFile
   set theWidth to do shell script ("/usr/local/bin/ffprobe -v error -of flat=s=_ -select_streams v:0 -show_entries stream=width " & theEpisode & " | cut -d \"=\" -f2")
   set theHeight to do shell script ("/usr/local/bin/ffprobe -v error -of flat=s=_ -select_streams v:0 -show_entries stream=height " & theEpisode & " | cut -d \"=\" -f2")
   set theResolution to space & "(" & theWidth & "x" & theHeight & ")"
   
   -- build new filename with extension
   set newEpisodeName to theEpisodeName & theResolution & "." & theExtension
   set name of theFile to newEpisodeName
   
end tell
brijazz
 
Posts: 21
Joined: Sun Mar 08, 2009 9:07 am

Re: Rename File Failing Fri Feb 25, 2022 10:23 am • by Mr_Noodle
Are the dimensions not already available via metadata? If so, it might be easier to use that. Otherwise, I'd recommend exporting custom attributes back out to Hazel. You can then use those in the Rename action.
Mr_Noodle
Site Admin
 
Posts: 11875
Joined: Sun Sep 03, 2006 1:30 am
Location: New York City

Re: Rename File Failing Fri Feb 25, 2022 10:34 am • by brijazz
Mr_Noodle wrote:Are the dimensions not already available via metadata?


Maybe? I didn't see an option for selecting width/height amongst available renaming attributes. The closest I can find is "Resolution (width/height): Resolution (width/heigh) of this image in DPI"
brijazz
 
Posts: 21
Joined: Sun Mar 08, 2009 9:07 am

Re: Rename File Failing Mon Feb 28, 2022 10:36 am • by Mr_Noodle
Is the Dimensions attribute not suitable in this case?
Mr_Noodle
Site Admin
 
Posts: 11875
Joined: Sun Sep 03, 2006 1:30 am
Location: New York City

Re: Rename File Failing Mon Feb 28, 2022 10:51 am • by brijazz
Mr_Noodle wrote:Is the Dimensions attribute not suitable in this case?


Hmm. I'm not seeing that as an available attribute when I search attributes after clicking 'other' in the rename field.

Image
brijazz
 
Posts: 21
Joined: Sun Mar 08, 2009 9:07 am

Re: Rename File Failing Tue Mar 01, 2022 9:56 am • by Mr_Noodle
If you select the file in Finder and do "Get Info", do you see it under "More Info"?
Mr_Noodle
Site Admin
 
Posts: 11875
Joined: Sun Sep 03, 2006 1:30 am
Location: New York City

Re: Rename File Failing Tue Mar 01, 2022 10:30 am • by brijazz
Mr_Noodle wrote:If you select the file in Finder and do "Get Info", do you see it under "More Info"?


For MP4 videos: yes
For MKV videos: no

Guessing that since MacOS doesn't natively support MKV files that any OS-level solutions won't work here?
brijazz
 
Posts: 21
Joined: Sun Mar 08, 2009 9:07 am

Re: Rename File Failing Wed Mar 02, 2022 9:45 am • by Mr_Noodle
It depends on the apps you have installed. You can try and search around for an app that handles mkv that also provides a Spotlight importer that will provide that info to the system.
Mr_Noodle
Site Admin
 
Posts: 11875
Joined: Sun Sep 03, 2006 1:30 am
Location: New York City

Re: Rename File Failing Wed Mar 02, 2022 9:54 am • by brijazz
Mr_Noodle wrote:It depends on the apps you have installed. You can try and search around for an app that handles mkv that also provides a Spotlight importer that will provide that info to the system.


I've just installed Filebot (which can handle MKV metadata) and can call it from the command line. Rolled it into my Hazel action and it's working perfectly. Thanks!
brijazz
 
Posts: 21
Joined: Sun Mar 08, 2009 9:07 am

Re: Rename File Failing Fri Mar 04, 2022 8:42 pm • by fmlisboajr
brijazz wrote:
Mr_Noodle wrote:It depends on the apps you have installed. You can try and search around for an app that handles mkv that also provides a Spotlight importer that will provide that info to the system.


I've just installed Filebot (which can handle MKV metadata) and can call it from the command line. Rolled it into my Hazel action and it's working perfectly. Thanks!



Hi, can you share how do you did these, please!
fmlisboajr
 
Posts: 13
Joined: Fri Sep 02, 2016 4:14 pm
Location: Portugal

Re: Rename File Failing Fri Mar 04, 2022 11:13 pm • by brijazz
fmlisboajr wrote:
brijazz wrote:I've just installed Filebot (which can handle MKV metadata) and can call it from the command line. Rolled it into my Hazel action and it's working perfectly. Thanks!

Hi, can you share how do you did these, please!


Sure. Here's what my action and embedded shell script look like.

[url]imgur.com/a/4cLEGPf[/url]

I also recommend taking a look at documentation for the Filebot CLI. Note also that Filebot requires a license.
brijazz
 
Posts: 21
Joined: Sun Mar 08, 2009 9:07 am


Return to Support

cron