I’m thinking about writing a script to run when I leave work at night so that a lot of my work is done for me when I get in in the morning. It involves
a.) taking a file name from a CSV text document created by our ad scheduling system (which I know how to do)
b.) searching out the file (when I won’t know the path) and
c.) opening it in Quark and EPSing it (which I also know how to do).
The problem lies in that the file I’m looking for could lie on any one of eight network drives, and though I know by looking at the ads which drive they should be on, there is nothing contained in the text file that would be able to tell a script where to look. The other problem is that Spotlight doesn’t index any of these drives, so even when I do a search using a Finder window or even PathFinder, the search takes anywhere from 10 seconds to 3 minutes, depending on where the file is located. As there are on average 60-100 ads per publication, and I’m usually working on at least 2 pubs at a time, this script would obviously take a long time to work, hence the overnight aspect. The script would also have to distinguish between a Quark file with no extension (ie, 1007142) and artwork for the file sharing the same ad number (ie, 1007142.tif). I think that should be fairly easy, since the filenames tend to be exactly the same as the number given in the text file. However, those files are often contained in a folder with exactly the same name, so obviously I don’t want Quark trying to open a folder, when it should be trying to open the file inside it.
Any ideas?
Hi relishgargler,
something like this¿
It’ll stopp after first match …
Hope it works!
set tid to AppleScript's text item delimiters
set MyFileName to "123456"
set MyVolumes to {alias "Volume1:", alias "Volume2:"}
repeat with i from 1 to count of MyVolumes
set CurrentVolume to item i of MyVolumes
set MyHits to do shell script "mdfind -onlyin '" & POSIX path of CurrentVolume & "'" & space & " -name '" & MyFileName & "'"
set x to every paragraph of MyHits
end repeat
repeat with j from 1 to count of x
set filePath to item j of x
set AppleScript's text item delimiters to "/"
if last text item of filePath is MyFileName then
set filePath to every text item of filePath
set AppleScript's text item delimiters to ":"
set filePath to filePath as text
set FileorFolder to folder of (info for alias filePath)
if FileorFolder is false then
return alias filePath
exit repeat
end if
end if
end repeat
set AppleScript's text item delimiters to tid
Interesting. I haven’t gotten into shell scripting yet. I’ll play around with this a little when I have a bit of free time and see how it goes. There is definitely some stuff in there I wouldn’t have thought of. Thanks!
If Spotlight hasn’t indexed the drives, mdfind will not find anything on them (since it’s the CLI for Spotlight).
So is there a way to force Spotlight to search for something beyond what it’s already indexed? I’m not too familiar with the internal workings of Spotlight (and it seems like they change dramatically with each OS version anyway)
Nope. But you could look at the common find function in Terminal. Check out the man page in Terminal and do a search for UNIX find and you’ll find a ton of easy info on it. Cheers!
Jim
Hi,
a possible find-solution … the first file matching the searchcriteria will cause an exit repeat.
returns an alias
may be you’ve got to do the shell command whith administrator privileges (look at the end of the do shell script line)
hope it works …
set tid to AppleScript's text item delimiters
set MyFileName to "123456"
set MyVolumes to {alias "Volume1:", alias "Volume2:"}
repeat with i from 1 to count of MyVolumes
set CurrentVolume to item i of MyVolumes
set MyHit to do shell script "find " & quoted form of POSIX path of CurrentVolume & " -type f -name '" & MyFileName & "'" & "|head -n 1" --user name "username" password "password" with administrator privileges
if MyHit is not missing value then
set AppleScript's text item delimiters to "/"
set filePath to every text item of MyHit
set AppleScript's text item delimiters to ":"
set filePath to alias ((text items 3 thru -1 of filePath) as text)
return filePath
exit repeat
end if
end repeat
set AppleScript's text item delimiters to tid