Setting Finder Label via osascript

Talk, speculate, discuss, pontificate. As long as it pertains to Hazel.

Moderators: Mr_Noodle, Moderators

Setting Finder Label via osascript Sun Jan 06, 2013 2:42 am • by scottfwalter
So this is what I want to do:

1. Extract the audio from a mp4 file via ffmpeg
2. Set the label color of the outputted file from step 1 to red

So this is what I have:
Code: Select all
#!/bin/sh

f="$1"
filename=$(basename "$f")
dirname=$(dirname "$f")
extension="${filename##*.}"
filename="${filename%.*}".m4a

/Users/scott/bin/ffmpeg -i "$f"  -vn -acodec copy "$dirname/$filename"
/usr/bin/osascript -e "tell application \"Finder\" to set label index of alias POSIX file (\"file://$dirname/$filename\") to 2"


Sometimes the label color will be set and other times it won't. Any ideas on why the label is not getting set consistently?
scottfwalter
 
Posts: 47
Joined: Thu Jan 03, 2013 11:10 am

Re: Setting Finder Label via osascript Mon Jan 07, 2013 4:02 pm • by Mr_Noodle
Is there a reason why you don't have Hazel setting the label for you?
Mr_Noodle
Site Admin
 
Posts: 11195
Joined: Sun Sep 03, 2006 1:30 am
Location: New York City

Re: Setting Finder Label via osascript Mon Jan 07, 2013 5:06 pm • by scottfwalter
I don't have Hazel set the label because I was watching for "mov" files and have my shell script via ffmpeg convert them to mp4 files as well as setting the color label.

Would the best practice be to create two rules: 1. for "mov" files to run my shell script and 2. for "mp4" files to change the color label?

Thanks for any advice, pretty new to Hazel so I may not know the best way to do things.
scottfwalter
 
Posts: 47
Joined: Thu Jan 03, 2013 11:10 am

Re: Setting Finder Label via osascript Tue Jan 08, 2013 4:50 pm • by Mr_Noodle
You could do that or if you use an AppleScript, you can have the script re-target which file is being processed (so that it re-targets the rule to use the mp4 file that is output). Search the help and forums for AppleScript on details on how to do this.
Mr_Noodle
Site Admin
 
Posts: 11195
Joined: Sun Sep 03, 2006 1:30 am
Location: New York City

Re: Setting Finder Label via osascript Tue May 21, 2013 8:39 am • by rohail1
> Just out of curiosity, why are you using osascript. Is there some
> reason you can't do this directly by using only the Finder?

This is just meant something I want to have as an optional toggle in a
shell script; no biggie if I can't get it to work in the script, but it
would be nice, and not worth having to go to AppleScript in addition.

> this may be something like your request
>
> tell application "Finder"
> set fold to choose folder
> set label index of (every file of (entire contents of fold) whose
> file type is "text") to 7
> set label index of (every folder of (entire contents of fold)) to 3
> set label index of fold to 3
> end tell

thanks, I will look at this.
rohail1
 
Posts: 1
Joined: Tue May 21, 2013 8:33 am

Re: Setting Finder Label via osascript Tue May 21, 2013 12:39 pm • by sjk
Where's the original post that you quoted in your reply, rohail1?

One of my recent replies in another topic mysteriously disappeared.

I'm starting to wonder if there a post-hungry gremlin on this forum …
sjk
 
Posts: 332
Joined: Thu Aug 02, 2007 5:43 pm
Location: Eugene

Re: Setting Finder Label via osascript Tue May 21, 2013 2:13 pm • by Mr_Noodle
Odd. I'm not seeing any record of the post being deleted by me. Is it possible you deleted it yourself somehow?
Mr_Noodle
Site Admin
 
Posts: 11195
Joined: Sun Sep 03, 2006 1:30 am
Location: New York City

Re: Setting Finder Label via osascript Tue May 21, 2013 7:50 pm • by sjk
My post that vanished was after a_freyer's first reply in this topic:

Applescript error while trying to move files with hazel

Most likely possibility is that it was unsuccessfully submitted after I'd previewed it a few times. It's very rare that I ever delete a post so if indeed this one was actually submitted the odds of accidental deletion are extremely low. AFAIK I've never done that with thousands of posts on any forum. :)

Only reason I mentioned it is because of rohail1's reply here that looks like it quotes some other post I couldn't find. But maybe that's a false assumption.

I'm fine with just dropping this issue (as an unknown but possible user error) unless I have more definitive evidence in the future that previously submitted posts are actually disappearing (e.g. have copies of them stored in a local DEVONthink database).
sjk
 
Posts: 332
Joined: Thu Aug 02, 2007 5:43 pm
Location: Eugene


Return to Open Discussion

cron