Hi
I want to be able to create watched folders, say from a button in my app.
I’ve been playing with things like the old AS way of using store script and attach action–something along the lines of:
script jKeywordAppDelegate
...
...
on watchFolder_(sender)
set FILE_PATH to quoted form of (POSIX path of (choose folder with prompt "Choose a file to watch" default location (path to desktop)))
set temp to (do shell script "echo " & quoted form of myscriptX & " > " & "/Library/Scripts/Folder Action Scripts/new1.scpt")
store script myscriptX in file ("/Library/Scripts/Folder Action Scripts/" & "new.scpt") replacing yes
tell application "System Events"
attach action to FILE_PATH using "new.scpt"
end tell
end watchFolder_
...
...
end script
script myscriptX
on adding folder items to thisFolder after receiving addedItems
--do stuff to the addedItems
end adding folder items to
end script
without much luck.
I’ve noticed some stuff in the OC Docs about folder watching, but it looks like overkill for my simple purpose.
Any ideas or help
Hi,
you’re mixing up all file specifier types
store script . in file expects a HFS file path
attach action to expects an alias, the parameter using a HFS file path
.
on watchFolder_(sender)
set folderActionScriptsFolder to path to Folder Action scripts from local domain as text
set FILE_PATH to (choose folder with prompt "Choose a file to watch" default location (path to desktop))
set folderActionScriptPath to (folderActionScriptsFolder & "new.scpt")
store script myscriptX in file folderActionScriptPath replacing yes
tell application "System Events"
attach action to FILE_PATH using folderActionScriptPath
end tell
end watchFolder_
.
Thanks for that, but my main problem seems to be getting the script that I want to attach recognized as a script.
I’ve run one-line scripts inside my delegate script, and I feel as though I should define the script-to-be-attached there, but it errors:
Any ideas?
Maybe I can’t mix and match AS and ASOC this way??
Thanks for any guidance
rhb
Oh yes AND I want to set data inside the script (I’ll be running a little shell script when files are added to the watched folder based on the data)
rhb
If you want to create custom applescripts, create a raw text file and compile it with /usr/bin/osacompile
Bloody brilliant!! (as we used to say back in the old country)
Thanks StefanK