Hello
I would like to know if its possible to create an Applescript that will alert the user when a paticular file is placed in a paticular folder.
The scenario is archived jobs being requested to be worked on again, the archived files are placed into a central folder for all our users to access. If each user could put an Applescripted “watch” onto the central folder it would save alot of time going backwards and forwards checking to see if it had arrived.
Any help appreciated
You can attach a folder action to the folder you want watched. It is called “add - new item alet.”
Hope that helps,
Steven.
Is there a way you can watch for a paticular file to be added?
Charlie,
You sure can. Compile and save the following as a stay-open script. Change the path to the watched folder, and the name of the file you are watching for.
This is tested works on OS 9.2
property watchedFolder : "Mac HD:Desktop Folder:Watched Folder:" --path to your watched folder
property watchFor : "Some File Name"--name of the file you are watching for
on idle --when the computer is idle
set folderContents to list folder watchedFolder without invisibles --get a list of the contents of your watched folder, without invisible files
if folderContents contains watchFor then --if the list of items contains the name of the file we are watching for then...
tell application "Finder"
activate --bring finder to the front so the dialog won't be hidden
--beep 3--optionally beep if you want to really command attention
--next, throw up a dialog about the files, give the user an option to go to the folder to see the files
display dialog "Hurry, " & watchFor & " is waiting for you!!" buttons {"Okay", "Go there"} default button 1 with icon note
end tell
if the button returned of the result = "Go there" then --if the button clicked is 'Go there', open the folder
tell application "Finder"
open folder watchedFolder --open the folder if requested
end tell
my quitSubroutine() --this will run the subroutine below to quit the script so the user isn't continually barked at
else if the button returned of the result = "Okay" then
my quitSubroutine() --again, the user knows there is a file there, quit until the user is done with the file and it is gone
end if
else --if there is nothing there
return 3 --check again in 3 seconds, or however long you want
end if
end idle
on quitSubroutine()
tell me to quit --quit the watch application
end quitSubroutine
You can also have it look and warn the user if there are more than 0 items in the watched folder but you appear to want it to look for a specific file.
Hope this helps!
Hey Charlie,
I have just the ticket. While I would lean towards Applescript, I have to say this approach is much cleaner, and is a real application.
One Trick Pony is a Stimpsoft Freeware product www.stimpsoft.com that does one thing very well, and that is after a doc (of any kind) is dropped into a watched folder, it sends an email to you.
You can configure it to send a blurb, and, as well as the email telling you what was dropped into the folder.
One Trick Pony is not being developed anymore, but I hear that a third party has picked it up. If you can’t find it, let me know and I’ll send ya a copy.
Enjoy :lol:
Thanks Ray, this program would be ideal…but I don’t have email on my Mac!!
The solution above yours works ok, are there such things as wildcards in Applescript. What I mean is, I know the ref number used in the file name its looking for, but it may be suffixed with a letter (i.e. 12345a, 12345b, 12345c and so on) is there a way to search for part of a file name?
Thanks for your help!
Charlie,
If your watched folder will only receive these “12345” files you really only need to look to see if the number of files in it are greater than 0. If you use that folder for other things then the script below will check to see if the # files in it are greater than 0 and check each file name to see if it contains your watch for text.
Best,
property watchedFolder : "Mac HD:Desktop Folder:Watched Folder:" --path to your watched folder
property watchFor : "12345"
on idle --when the computer is idle
set folderContents to list folder watchedFolder without invisibles --get a list of the contents of your watched folder, without invisible files
if the number of items in folderContents > 0 then --if there are more than 0 items in the folder
--if this folder will only receive your "12345" files then you really only need to look to see if there are more than 0 files
--you could just use the last script posted but change the if statement to read "If the number of items in folderContents >0"
--Otherwise, this will watch for items and check each one to see if the name contains the watch for text
repeat with thisItem in folderContents --repeat with the name of every item found in the folder
if thisItem contains watchFor then --if this item contains the watchFor text then do the thing with the thing
tell application "Finder"
activate --bring finder to the front so the dialog won't be hidden
--beep 3--optionally beep if you want to really command attention
--next, throw up a dialog about the files, give the user an option to go to the folder to see the files
display dialog "Hurry, " & watchFor & " is waiting for you!!" buttons {"Okay", "Go there"} default button 1 with icon note
end tell
if the button returned of the result = "Go there" then --if the button clicked is 'Go there', open the folder
tell application "Finder"
open folder watchedFolder --open the folder if requested
end tell
my quitSubroutine() --this will run the subroutine below to quit the script so the user isn't continually barked at
else if the button returned of the result = "Okay" then
my quitSubroutine() --again, the user knows there is a file there, quit until the user is done with the file and it is gone
end if
end if
end repeat
else --if there is nothing there
return 3 --check again in 3 seconds, or however long you want
end if
end idle
on quitSubroutine()
tell me to quit
end quitSubroutine