Page 1 of 1

Passing variable / token to applescript

PostPosted: Tue Jun 12, 2012 8:16 am
by chezbiscuit
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

Re: Passing variable / token to applescript

PostPosted: Tue Jun 12, 2012 1:01 pm
by a_freyer
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.

Re: Passing variable / token to applescript

PostPosted: Fri Jun 15, 2012 10:58 am
by chezbiscuit
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.

Re: Passing variable / token to applescript

PostPosted: Tue Jun 19, 2012 3:58 pm
by Mr_Noodle
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.

Re: Passing variable / token to applescript

PostPosted: Thu Jun 21, 2012 7:21 am
by chezbiscuit
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.

Re: Passing variable / token to applescript

PostPosted: Tue Oct 09, 2012 9:05 am
by jnthnclrk
+1

This would be super handy.

Re: Passing variable / token to applescript

PostPosted: Wed Oct 10, 2012 1:01 pm
by a_freyer
I've posted a tutorial on how to do this here.

Re: Passing variable / token to applescript

PostPosted: Thu Oct 11, 2012 8:36 am
by Beaver
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.

Re: Passing variable / token to applescript

PostPosted: Thu Oct 11, 2012 4:09 pm
by Mr_Noodle
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.

Re: Passing variable / token to applescript

PostPosted: Fri Oct 12, 2012 3:38 am
by Beaver
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.

Re: Passing variable / token to applescript

PostPosted: Fri Aug 23, 2013 6:39 am
by marceltrapman
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.

Hi, are you still considering this?

I've read the post 'Pass Hazel Variables to Applescript' but although creative it is a bit too tricky for my tasting.

When you would implement it I could throw away a couple of scripts that are almost the same.

Re: Passing variable / token to applescript

PostPosted: Fri Aug 23, 2013 12:32 pm
by Mr_Noodle
Yes, though it's not a high priority item and not straightforward to do, especially with the shell script case.

Re: Passing variable / token to applescript

PostPosted: Tue Aug 27, 2013 3:56 pm
by s6t
Hello Mr.Noodle

does this exist?
I asked in another forum but then I found this. That is exactly what I want.

Did you implement this already?
Is there any documentation?
thanks

Re: Passing variable / token to applescript

PostPosted: Wed Aug 28, 2013 3:24 pm
by Mr_Noodle
As mentioned before, it's under consideration so it's not implemented yet.

Re: Passing variable / token to applescript

PostPosted: Wed Aug 28, 2013 5:08 pm
by a_freyer
a_freyer wrote:I've posted a tutorial on how to do this here.



Has no one seen the reply I made in this thread?

This is already possible, explained in a tutorial I wrote a while ago.