Changing "open with" application with Hazel rule?

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

Moderator: Mr_Noodle

Is there a way to have Hazel change the "open with" application for a file when a rule matches?

I want most of my PDFs to open in Preview. But any PDF that I add to a particular folder, I'd like to set to open in Acrobat XI Pro.

Presumably this would involve running a script on matched files, but I'll be damned if I can figure out how to script that.

So two questions...

a) how do I script that?

b) seems like a useful action for Hazel to have built in; how can I request it?
roosterboy
 
Posts: 4
Joined: Wed Jan 22, 2014 1:48 am

In the "Open" action, just click on the pop-up and select "Other...".
Mr_Noodle
Site Admin
 
Posts: 11255
Joined: Sun Sep 03, 2006 1:30 am
Location: New York City

Except that opens the file, which isn't what I want to do.

Maybe I wasn't clear in my initial question. I don't want to open files that match the rule; I want to set the application that will open them tomorrow or next week or a year from now, whenever I double-click on the file in Finder. Basically, as if I had opened the Info window for each matching file and manually set the open with dropdown but, y'know, without actually having to do that manually.

Used to be, in the pre-OS X days, we could set a file's creator code using AppleScript to do this. Using mdls on a file shows there's a kMDItemFSCreatorCode attribute but it doesn't seem to have much effect in my (admittedly limited so far) testing. As far as I've been able to figure out, that info is now stored in the com.apple.FinderInfo extended attribute, but I can't find any way to set it.

So is there any way to script this, which would mean I could include it in a run script action in Hazel?

Also, it seems like this would be a useful addition to the available actions in Hazel.
roosterboy
 
Posts: 4
Joined: Wed Jan 22, 2014 1:48 am

Ah, I see. Yes, you'll need to use a script to do that though I don't know off-hand the way to do that so you'll have to google around. I'll consider it as a built-in action though I'm not sure how common it is to make it a worthwhile addition.
Mr_Noodle
Site Admin
 
Posts: 11255
Joined: Sun Sep 03, 2006 1:30 am
Location: New York City

Cool, thanks.

I was able to get it done with Automator's Set Application for Files action. I tried it with an AppleScript using the default application property of System Events' file object but could not get it to work no matter what I tried or how I reworded it. Oh well.
roosterboy
 
Posts: 4
Joined: Wed Jan 22, 2014 1:48 am


Return to Support