Growl Notifications

Anyone know how to get a file name from a repeat loop to display in a Growl notification? I have a folder set up that automatically moves any file placed in it into a folder on a network drive after a certain amount of time. I set it up in Automator, but it always bugged me that the Growl notification wouldn’t display WHICH file has been moved, but just a preprogrammed message. I figured it would be easy in Applescript, but I’m running into a wall.


set icon_file to "2074:Users:admin:Desktop:eps.png" as alias
set FilePath to (path to desktop as string) & "1" as alias

try
	tell application "Finder"
		set fileList to every file of folder FilePath as alias list
	end tell
end try

try
	repeat with aFile in fileList
		tell application "GrowlHelperApp"
			-- Make a list of all the notification types 
			-- that this script will ever send:
			set the allNotificationsList to ¬
				{"EPS_Moved"}
			
			-- Make a list of the notifications 
			-- that will be enabled by default.      
			-- Those not enabled by default can be enabled later 
			-- in the 'Applications' tab of the growl prefpane.
			set the enabledNotificationsList to ¬
				{"EPS_Moved"}
			
			-- Register our script with growl.
			-- You can optionally (as here) set a default icon 
			-- for this script's notifications.
			register as application ¬
				"Move EPS" all notifications allNotificationsList ¬
				default notifications enabledNotificationsList ¬
				icon of application "Script Editor"
			
			--	Send a Notification...
			notify with name ¬
				"EPS_Moved" title ¬
				"EPS file moved" description ¬
				aFile & " has been moved to Archive:EPS ADS" application name ¬
				"Move EPS" image from location icon_file
		end tell
	end repeat
end try

HAH! Never mind. I just figured it out. I’ll still post in case someone else has the same problem…

I changed the line

aFile & " has been moved to Archive:EPS ADS" application name ¬

to

(aFile & " has been moved to Archive:EPS ADS") as string application name ¬

and it worked like a charm. The first line would give me the proper notifications, but with blank text. The second line gives me something like “2074:Users:admin:Desktop:1:998765.eps has been moved to Archive:EPS ADS”.

Now that I have that figured out, it should be simple to modify the code to strip out the file path and just give me the file name.

You’re lucky your solution worked. I don’t think you’re actually doing it properly but I guess applescript is figuring out what you actually wanted and doing it for you. I’m talking about this line…

(aFile & " has been moved to Archive:EPS ADS") as string

Here’s the problem. Using the “&” operator to add 2 strings together means each thing you are adding has to be a string. You can’t add a file alias to a string. That’s what you were originally doing. You can only add a string to a string. So in your case what you needed to do was coerce aFile (the file alias) to a string and then add the 2 strings. This is what you meant to do…

(aFile as string) & " has been moved to Archive:EPS ADS"

And just to be totally correct, aFile is not the actual alias. The way you use the repeat loop, aFile is a reference to an item in the list, and that item is an alias. To get the actual value of the reference you use “contents”. So in total your code would look like this…

(contents of aFile) as string & " has been moved to Archive:EPS ADS"

And finally, the term “string” is deprecated. We use “text” now since applescript became unicode text aware. So in all this is it…

(contents of aFile) as text & " has been moved to Archive:EPS ADS"

I only mention these things to teach you, so I hope it helps. :stuck_out_tongue:

Thanks for the lesson. All my knowledge of Applescript comes from this forum and the first chapter of Applescript 1-2-3 from the online tutorial. My boss is “thinking about” getting the book for me. We’ll see I guess.

One question though, is “string” a deprecated term as of 10.4, or just Leopard or Snow Leopard? We are still stuck with Tiger at work, which is what I was programming for. I’ve got some vague fuzzy memory of my scripts not liking “as text” quite the same as “as string”, but it could easily have been because my code was wrong at the time.

Glad to help. I believe you’re right that “text” is 10.5 or later. In 10.4 I was using “string” or Unicode text". FYI: here’s a good list of tutorials.
http://macscripter.net/viewtopic.php?id=25631