Posted: Fri Jan 21, 2005 11:01 am Post subject: applescript help, or why i was almost a genius
ok. so i did a search one day for all of my neo-docs straight from the finder. it was great, there in that folder was everything (even docs with the same name)
so i got to thinking about folder actions and the light bulb went on. i should be able to make a folder that does that automatcially when i start it. i started reading up on applescript, and folder actions. wrote some code, which didn't work.
here is the thing, i can't figure out how to call the finder's search function, or if i can't, how to search the hdd for files and list them in the folder.
Posted: Sat Jan 22, 2005 2:41 am Post subject: Re: applescript help, or why i was almost a genius
jakeOSX wrote:
ok. so i did a search one day for all of my neo-docs straight from the finder. it was great, there in that folder was everything (even docs with the same name)
so i got to thinking about folder actions and the light bulb went on. i should be able to make a folder that does that automatcially when i start it. i started reading up on applescript, and folder actions. wrote some code, which didn't work.
here is the thing, i can't figure out how to call the finder's search function, or if i can't, how to search the hdd for files and list them in the folder.
anyone have thoughts?
It is not clear to me exactly which part of this puzzle you need help with.
With folder actions, you need to write script handlers for specific actions that get attached to the folder of interest - these actions can be when the folder's window is opened/closed/moved/resized, and when files are added/deleted to/from the folder. You can do things like launch applications for the items newly added to the folder.
I believe the window associated with the results of a Finder "Find" is NOT a window belonging to a real folder, so even you were able to script "Find", you couldn't attach folder actions to the results "folder".
I don't think "Find" is directly scriptable. You might be able to script Sherlock to do a Internet search of the local "file:///Volumes" URL.
Personally I would just use (assuming for the moment this is for your use on your machine, since it might require the BSD subsystem to be installed, and you would need additional checking in a script that other people may use) the command line "find" tool with the AppleScript "do shell script" command.
e.g.
set list_of_writer_files to do shell script "find / -name \"*.sxw\""
Having found the files, I don't know what you need to do with them - folder action scripts are not really required. You could copy/move the found files, or create aliases/symlinks to the found files, or you could open the found files directly in the application of your choice.
Where it gets tricky, is the conversions between POSIX pathnames ("/Volumes/Mac HD/thisfile"), Mac OS pathnames ("Mac HD:thisfile"), and URLs (file:///Volumes/Mac%20HD/thisfile), needed by the various pieces involved in the solution, dealing with UTF-8 filenames, shell quoting, AppleScript/shell quoting etc.
Mac OS X comes with a complete set of AppleScript examples, including folder actions - suggest you install the Script Menu extra that you can find in the /Applications/AppleScript folder.
Posted: Sat Jan 22, 2005 4:23 am Post subject: Re: applescript help, or why i was almost a genius
Terry Teague wrote:
I believe the window associated with the results of a Finder "Find" is NOT a window belonging to a real folder, so even you were able to script "Find", you couldn't attach folder actions to the results "folder".
It is a real folder, of sorts. If you switch Find to find visible and invisible files, the first result will be .Search Results.... in /private/tmp/ (it finds itself!) You can add it to your sidebar, but I think it's both static and temporary (is killed when you close Find). (When one does finally get to <tt>ls</tt> it, it seems to contain only . and .., not even symlinks to the files it finds/"contains.")
All of this is totally useless but somehow interesting
Isn't something like what you want supposed to be in 10.4? Or do what Terry says. Terry is the AppleScript guru!
jakeOSX wrote:
applescript help, or why i was almost a genius
I feel the same way every time I sit down to do something in AppleScript. I remain in awe of Terry.
Smokey _________________ "[...] whether the duck drinks hot chocolate or coffee is irrelevant." -- ovvldc and sardisson in the NeoWiki
Posted: Sun Jan 23, 2005 8:53 am Post subject: Re: applescript help, or why i was almost a genius
Terry Teague wrote:
I believe the window associated with the results of a Finder "Find" is NOT a window belonging to a real folder, so even you were able to script "Find", you couldn't attach folder actions to the results "folder".
thanks terry, i think that answers the question. basically i wanted a folder action so that when i opened this certain folder it was the same as doing a search for *.sxw.
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum You cannot attach files in this forum You cannot download files in this forum