i’m trying to find the most recent saved file from a particular app. (probably limited to somewhere within the users folder if it will speed things up)
i’d post all of my attempts so far but i’m a little embarrassed by them
there might be a little more to my needs but maybe we can start with just locating the file ?
[other requirements, i think, will be making sure the file was saved within the last 30 seconds or so… if not, wait til one has been…?]
If you are lucky, there is a plist with recently used documents in your preferences folder for that app.
Else mdfind might be an option.
kMDItemKind allows to specify the application, there are kMDItemFSContentChangeDate and kMDItemFSCreationDate to restrict the time of creation and change.
Use mdls on a file to see the available properties.
Finding examples for the syntax is trickier. It is spread over man pages and several web pages.
this app (sketchup) does have a plist for recent items… unfortunately, it doesn’t seem to update immediately upon saving a new file… so that’s not going to work…
(basically, what i’m trying to accomplish is giving the .skp file a 512px icon upon saving… i’ve got most of it worked out so far… now it’s just a matter of getting the newly saved file so i can assign the icon to it)
the solution i’m going with at this point is via getting the title of the frontmost drawing window (whose name updates immediately upon ‘save’ or ‘save as’ then mdfind (thx juergen) to figure out where exactly the file is…
here’s this part of the script so if anyone has sketchup, maybe they can test it out to make sure it’s working on environments other than my own computer… (or, maybe someone knows of a better method?)
thanks
tell application "SketchUp"
activate
tell application "System Events" to tell process "SketchUp"
--identify the frontmost drawing window (drawwin)
set drawwin to 0
set cw to 1 + (count of windows)
repeat until drawwin ≠0
set cw to (cw - 1)
if value of attribute "AXmain" of window cw is true then
set drawwin to cw
end if
end repeat
--get the window's title then find the text before ".skp"
--this should work on both sketchup pro and free ?
--also shouldn't matter if the user has a space or period within the title name?
set WinTitle to title of window drawwin
set AppleScript's text item delimiters to {".skp"}
set skpFILE to first text item of WinTitle & ".skp"
--find the .skp using mdfind
do shell script "mdfind -name " & skpFILE
end tell
end tell
thanks for the help!
[edit]… hmm, actually, this could be a problem if there is another file by the same name on the system… i suppose i’ll can check the creation time to make sure it’s recently created (or opened, or modified, or something ) ??