Run AppleScript: How to use hazelExportTokens?

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

Moderator: Mr_Noodle

Run AppleScript: How to use hazelExportTokens? Sat Mar 03, 2012 11:12 am • by Farthen
Hi,

I tried creating an AppleScript that is returning a record with hazelExportTokens as it is described in the help. The script is as simple as possible:

Code: Select all
return {hazelExportTokens:{test:"test"}}

Image

I clicked the little i on the top right corner and added test as a token. Then I added another rule that sorts it into the folder with the the name specified by the token test
Image

Problem: test seems to be empty. any idea why this is the case? I'm kinda new to AppleScripts so please tell me if I do something completely wrong :)

EDIT: I just found out that the "passes shell script" rules don't work for me either. There seems to be some issue with parsing return codes on my machine.
Farthen
 
Posts: 4
Joined: Wed Jul 20, 2011 8:11 pm

Looking into it. It was one of the least tested features, probably. I'll see if I can fix it before tomorrow's patch.
Mr_Noodle
Site Admin
 
Posts: 11262
Joined: Sun Sep 03, 2006 1:30 am
Location: New York City

Ok, I fixed the issue with the export tokens.

The passes Applescript works for me. Could you send me a case where it isn't working?
Mr_Noodle
Site Admin
 
Posts: 11262
Joined: Sun Sep 03, 2006 1:30 am
Location: New York City

Thanks for fixing this issue, works great now.

To the other issue: "Passes AppleScript" works fine, I was talking about "Passes shell script":

Image
Image

The growl notification isn't triggered at all. :)
Farthen
 
Posts: 4
Joined: Wed Jul 20, 2011 8:11 pm

Ah ok. Looking into it. Thanks.
Mr_Noodle
Site Admin
 
Posts: 11262
Joined: Sun Sep 03, 2006 1:30 am
Location: New York City

Actually, it does work. The problem is that you should be using "return 0" but "exit 0" instead. I've fixed the documentation to be a bit clearer on this.
Mr_Noodle
Site Admin
 
Posts: 11262
Joined: Sun Sep 03, 2006 1:30 am
Location: New York City

I am evaluating Hazel before purchase and probably will purchase, but I choose one of the more complex filename transformations to test. It requires looking inside the PDF file and coming up with the new filename. I an external AppleScript written to create the new filename and make use of the ExportTokens to pass the name back for rename. I know I could rename it in the AppleScript, but I thought I would test ExportTokens in case I have a future use.

I have two problems, the first is that it seems to pass the same information back in all the variables although I didn't test this with debug mode.

Second, I am now passing only a single variable back and it seems to get corrupted. As you can see in the log below the correct value with leading zeros in the date is passed back but the leading zeros are mysteriously stripped before I growl the alert. I am not adding the actual rename to the rule until I see the correct value in the variable.

2012-03-16 09:21:56.360 hazelworker[63451] DEBUG: Initialized
2012-03-16 09:21:56.360 hazelworker[63451] DEBUG: Pausing to wait for things to settle down.
2012-03-16 09:21:58.361 hazelworker[63451] DEBUG: Processing directories: (
"/Users/alanwyman/Downloads/hazeltest"
)
2012-03-16 09:21:58.367 hazelworker[63451] DEBUG: About to process directory /Users/alanwyman/Downloads/hazeltest
2012-03-16 09:21:58.379 hazelworker[63451] DEBUG: [PREDICTION] Calculating fire time - predicate: ANY sources LIKE[cd] "*Xcelenergy.com*" negation: 0 result: 1
2012-03-16 09:21:58.379 hazelworker[63451] DEBUG: [PREDICTION] Next fire time: 5828963-12-20 00:00:00 +0000
2012-03-16 09:21:58.379 hazelworker[63451] DEBUG: [PREDICTION] Calculating fire time - predicate: displayBasename BEGINSWITH[cd] "Xcel" negation: 1 result: 1
2012-03-16 09:21:58.379 hazelworker[63451] DEBUG: [PREDICTION] Next fire time: 5828963-12-20 00:00:00 +0000
2012-03-16 09:21:58.381 hazelworker[63451] Statement_317335885-1.pdf: Rule Copy of XcelStatementRename matched.
2012-03-16 09:21:58.381 hazelworker[63451] DEBUG: Manual run. Forcing actions to be executed.
2012-03-16 09:21:58.994 hazelworker[63451] DEBUG: AppleScript XcelStatementsNamer.scpt executed successfully with file /Users/alanwyman/Downloads/hazeltest/Statement_317335885-1.pdf. Result: <NSAppleEventDescriptor: { 'usrf':[ 'utxt'("hazelExportTokens"), { 'usrf':[ 'utxt'("FileNameStr"), 'utxt'("Xcel_2012_03_08.pdf") ] } ] }>
2012-03-16 09:21:58.996 hazelworker[63451] Hazel Alert: Renaming Statement_317335885-1.pdf to *Xcel_2012_3_8.pdf*
2012-03-16 09:21:58.997 hazelworker[63451] [Custom Message] Hazel Alert: Renaming Statement_317335885-1.pdf to *Xcel_2012_3_8.pdf*
2012-03-16 09:21:58.997 hazelworker[63451] DEBUG: Action changed file: Statement_317335885-1.pdf
2012-03-16 09:21:58.998 hazelworker[63451] DEBUG: [PREDICTION] Predicted fire time for file: /Users/alanwyman/Downloads/hazeltest/Statement_317335885-1.pdf and rule Copy of XcelStatementRename: 5828963-12-20 00:00:00 +0000
2012-03-16 09:21:59.001 hazelworker[63451] DEBUG: Directory /Users/alanwyman/Downloads/hazeltest processed.
2012-03-16 09:21:59.002 hazelworker[63451] Sending metrics to scheduler. Next scheduled run: 5828963-12-20 00:00:00 +0000
2012-03-16 09:21:59.002 hazelworker[63451] DEBUG: Done
manofwy
 
Posts: 11
Joined: Fri Mar 16, 2012 10:26 am
Location: White Bear Township, MN

Wow, this is a weird one. Took me a bit until I realized what may be happening.

When you create a custom token, Hazel tries to figure out its "type". For other attributes, Hazel knows that this is text, or a number, or a date, etc. With custom tokens, Hazel makes a determination based on what tokens the custom token is comprised of.

Right now, if there are any number tokens in it, it considers it a number. It also considers it text as well if it has regular alpha characters in it. When you click on the token in the replace pattern, you'll see you have options to format it both as a number and as text.

So, if you are still following me, for the moment, you should be able to get your digits back by clicking on the custom token and setting the minimum number of digits to 2 (or "00").

I'm thinking that maybe I should be stricter about classifying something as a number. Maybe a number should only have number tokens in it (and maybe symbols). If it's mixed in with alpha characters, do not treat is as a number.
Mr_Noodle
Site Admin
 
Posts: 11262
Joined: Sun Sep 03, 2006 1:30 am
Location: New York City

That makes sense, however, there is not a formatting option on the custom token. When I clock on it, it does nothing. I do see a drop down arrow on name and extension.
manofwy
 
Posts: 11
Joined: Fri Mar 16, 2012 10:26 am
Location: White Bear Township, MN

Ah right. This is being exported from an AppleScript so Hazel has no way to interpolate what type it is. So, there is some bug where it is formatting them as numbers regardless. I'll take a closer look at it. Thanks for the report.
Mr_Noodle
Site Admin
 
Posts: 11262
Joined: Sun Sep 03, 2006 1:30 am
Location: New York City

BTW, it may be a while before another patch is released. If you find this urgent, email support and I'll send you a link to a test build with a fix in.
Mr_Noodle
Site Admin
 
Posts: 11262
Joined: Sun Sep 03, 2006 1:30 am
Location: New York City

How to make an executable program from AppleScript?
In order to run my AppleScript program I have to open it up and select "run." I want the program to just run when I click on it. I tried to compile it, but it didn't seem to make a difference or create a new file.
jamesbrownsfhs
 
Posts: 1
Joined: Thu May 10, 2012 5:02 am

I'm not sure why you want to do this with respect to Hazel. Hazel does not require the AppleScript to be a stand alone program for Hazel to run it. If you want be able to run it by double-clicking in Finder, you need to check the help for the AppleScript Editor.
Mr_Noodle
Site Admin
 
Posts: 11262
Joined: Sun Sep 03, 2006 1:30 am
Location: New York City

I don't know if this is still the earlier bug or something that broke in a later release. I had not tried to rename a file to a name starting with digits before. I attempted to name it with the year and month first and it did not return the name. For example 2012-11_util_cell.pdf was returned as blank. When I tested the embedded script with it creating the name xx2012-11_util_cell.pdf it works fine. I am currently running version 3.0.15 (build 882).
manofwy
 
Posts: 11
Joined: Fri Mar 16, 2012 10:26 am
Location: White Bear Township, MN

I don't think your problem is related. Post more details like the script you are using.
Mr_Noodle
Site Admin
 
Posts: 11262
Joined: Sun Sep 03, 2006 1:30 am
Location: New York City

Next

Return to Support