Run AppleScript: How to use hazelExportTokens?

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

Moderator: Mr_Noodle

Here is the script

-- Set up log file
set crlf to (ASCII character 13) & (ASCII character 10)
set fp to open for access file "Macintosh HD:Users:manofwy:ScriptLogs:util_cell.txt" with write permission
-- Retrieve filename
tell application "Finder"
set filename to (name of theFile) as string
end tell
write "Filename ->" & filename & "<-" & crlf & crlf to fp
-- Striping out the year from the original name
set ptrYear to ((offset of "_" in filename) + 1 as integer)
set ptrYear2 to ptrYear + 3
set year4 to (characters ptrYear thru ptrYear2 of filename)
write "Year ->" & year4 & "<- (" & ptrYear & "," & ptrYear2 & ")" & crlf to fp
-- Striping out the month from the original name
set ptrMon to ptrYear + 4
set ptrMon2 to ptrMon + 1
set month2 to (characters ptrMon thru ptrMon2 of filename)
write "Month ->" & month2 & "<- (" & ptrMon & "," & ptrMon2 & ")" & crlf to fp
-- Put the name back together
set newName to "xx" & year4 & "-" & month2 & "_util_cell"
write "newName ->" & newName & "<-" & crlf to fp
close access fp
return {hazelExportTokens:{newFilename:newName}}


The characters in blue are the only change I made between not working and working. My log file shows the correct filename in newName after the set.

Before the log file gets blamed for opening another file in the script, I added that after it already was not working to see what was going on. I also commented it out during some tests.

It really seems to be related to starting newName with digits instead of alpha.
manofwy
 
Posts: 11
Joined: Fri Mar 16, 2012 10:26 am
Location: White Bear Township, MN

Here is the log file to go with the previous post

Filename ->731166995_20121121.pdf<-

Year ->2012<- (11,14)
Month ->11<- (15,16)
newName ->xx2012-11_util_cell<-
manofwy
 
Posts: 11
Joined: Fri Mar 16, 2012 10:26 am
Location: White Bear Township, MN

You may want to try stripping it down. For instance, I just did a quick script as follows:
Code: Select all
return {hazelExportTokens:{blah:"11-abc"}}

And that seems to work on my end.
Mr_Noodle
Site Admin
 
Posts: 11865
Joined: Sun Sep 03, 2006 1:30 am
Location: New York City

That actually caused me to find the problem. The fact that the example had quotes around the string made me realize that I had not made sure the final variable was a string. Adding as string to the end of the line corrected the problem. Thanks.

The final script has the final set as:
set newName to year4 & "-" & month2 & "_util_cell" as string
manofwy
 
Posts: 11
Joined: Fri Mar 16, 2012 10:26 am
Location: White Bear Township, MN

Previous

Return to Support