Passing variable / token to applescript

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

Moderator: Mr_Noodle

Passing variable / token to applescript

Postby chezbiscuit » Tue Jun 12, 2012 8:16 am

New to Hazel (technically longtime returning user), so hope this isn't too stupid a question.

I'd like to be able to pass a variable / token to Applescript to use.

My particular use case is in importing images into Aperture where I may not know the Project name in advance (or it even exists). This doesn't seem possible with the regular 'import into Aperture' command, so my thinking is to hand off to Applescript, passing it the variable (a combo of a piece of the filename and date), then have it do the creation and import.

Is this possible?

I've also set up a script that allows me to pass text input to hazel for use in processing - is there an easier way of doing this? (e.g. when sorting images, it asks for a freeform text 'type', then sorts into folders based on this).

Thanks
chezbiscuit
 
Posts: 5
Joined: Wed Nov 29, 2006 6:23 am

Re: Passing variable / token to applescript

Postby a_freyer » Tue Jun 12, 2012 1:01 pm

The short answer is yes, both of these are possible. You should refer to the help for 'matching' and 'applescript'.

The 'help' is not part of the forum, but rather accessible by clicking the easily-missed question mark in the bottom right hand corner of the preference pane.

EDIT - Ah, I answered too fast before reading the question. My apologies. I'd suggest passing a var in the file name and renaming the file after the script.
Last edited by a_freyer on Thu Jun 21, 2012 7:09 pm, edited 1 time in total.
a_freyer
 
Posts: 584
Joined: Tue Sep 30, 2008 9:21 am
Location: Colorado

Re: Passing variable / token to applescript

Postby chezbiscuit » Fri Jun 15, 2012 10:58 am

a_freyer wrote:The short answer is yes, both of these are possible. You should refer to the help for 'matching' and 'applescript'.

The 'help' is not part of the forum, but rather accessible by clicking the easily-missed question mark in the bottom right hand corner of the preference pane.


Thanks, I've gone through both, but fail to see a way to pass a variable on to the Applescript. There's "hazelExportTokens" for passing FROM the Applescript, but I'm talking about passing to it. All that the help file illudes to is passing on an alias to the the file that matched, but nothing else.

Could you illustrate where in the help this is covered? Alternately some example code should be enough to get me going.
chezbiscuit
 
Posts: 5
Joined: Wed Nov 29, 2006 6:23 am

Re: Passing variable / token to applescript

Postby Mr_Noodle » Tue Jun 19, 2012 3:58 pm

You can't pass variables from Hazel to AppleScript at the moment. I'm considering adding it in a future release though it will break current handlers so I need to figure out a way to transition things over if I do it.
Mr_Noodle
Site Admin
 
Posts: 2967
Joined: Sun Sep 03, 2006 1:30 am
Location: New York City

Re: Passing variable / token to applescript

Postby chezbiscuit » Thu Jun 21, 2012 7:21 am

Mr_Noodle wrote:You can't pass variables from Hazel to AppleScript at the moment. I'm considering adding it in a future release though it will break current handlers so I need to figure out a way to transition things over if I do it.


Thanks Mr_Noodle - a pity but as I suspected.

It now occurs to me that I could 'populate' the filename of the file passed with the variables I need, have the applescript pick them up for use, and strip from the filename.

I do hope you add passing of variables, though understand that may be challenging.
chezbiscuit
 
Posts: 5
Joined: Wed Nov 29, 2006 6:23 am

Re: Passing variable / token to applescript

Postby jnthnclrk » Tue Oct 09, 2012 9:05 am

+1

This would be super handy.
jnthnclrk
 
Posts: 1
Joined: Tue Oct 09, 2012 8:54 am

Re: Passing variable / token to applescript

Postby a_freyer » Wed Oct 10, 2012 1:01 pm

I've posted a tutorial on how to do this here.
a_freyer
 
Posts: 584
Joined: Tue Sep 30, 2008 9:21 am
Location: Colorado

Re: Passing variable / token to applescript

Postby Beaver » Thu Oct 11, 2012 8:36 am

You can't pass variables from Hazel to AppleScript at the moment. I'm considering adding it in a future release though it will break current handlers so I need to figure out a way to transition things over if I do it.


Please do not leave shell scripts behind. Actually, for shell scripts the implementation could be as simple as an additional text box to specify optional parameters (including tokens) to pass to the shell script. Within the script these would be accessible as $2, $3 and so on. This would also not break compatibility to existing scripts.
Beaver
 
Posts: 2
Joined: Wed Oct 10, 2012 3:38 pm

Re: Passing variable / token to applescript

Postby Mr_Noodle » Thu Oct 11, 2012 4:09 pm

Noted and yes, it is actually easier for shell scripts since they don't have a strict calling signature. Unfortunately, it's a bit more difficult to implement the other direction since there's no good way for a shell script to output a dictionary/record with key value pairs.
Mr_Noodle
Site Admin
 
Posts: 2967
Joined: Sun Sep 03, 2006 1:30 am
Location: New York City

Re: Passing variable / token to applescript

Postby Beaver » Fri Oct 12, 2012 3:38 am

Unfortunately, it's a bit more difficult to implement the other direction since there's no good way for a shell script to output a dictionary/record with key value pairs.


Yeah, I have been thinking about that too. Here even the covert channel of passing stuff inside the file name (an ugly hack anyway) does not work, as the script is supposed to not change the file name (if I am taken right, have been using Hazel for just two days so far.)

Well, technically getting stuff out of the script should not be a big deal. Just let the script echo`ing <token>=<value> lines into a $HAZEL_PIPE that is read back by Hazel. However, I guess your concern is more about the usage interface and file IO is, interface-wise, not exactly what you are up too (even though that might be great for power users!).

A more user-friendly interface might be to let the script export variables with a magic name and have a small helper utility that the user has to invoke at the end of the script to perform the actual transport into Hazel.

Code: Select all
# cool script
export HAZEL_<token1>=<value>
export HAZEL_<token2>=<value>
# ...
# actually export to Hazel
backToHazel


backToHazel could then do the IO over $HAZEL_PIPE.
Beaver
 
Posts: 2
Joined: Wed Oct 10, 2012 3:38 pm


Return to Support

Who is online

Users browsing this forum: Google [Bot] and 1 guest



Copyright © 2006-2012 Noodlesoft, LLC, All Rights Reserved. Mac and the Mac logo are trademarks of Apple Computer, Inc., registered in the U.S. and other countries.