I want to make an applescript that sits in the side strip of the finder window. Thats the easy part. When I drag a file or folder to this applescript the file or folder should be moved to the previous folder.
For example I open the folder “Macintosh HD:Applications:” then I drag the file or folder to the applescript and the file is moved to “Macintosh HD:” because its the previos folder. I hope someone can help me with this, it could prove to be very useful.
You should add some error checking to the script so that it will tell you if an item with that name already exists…
on open list_of_files
try
tell application "Finder" to move list_of_files to parent of target of window 1
on error theErr
display dialog theErr buttons {"OK"} default button 1
end try
end open
It’s good that Greg mentioned error checking because there could be a lot that could go wrong in that script. Duplicate file names, permission issues, the window could already be the root drive and, as such, have no parent, “window 1” might not even be a Finder window, it could be the “Emptying Trash…” window or a “Get Info” window.
ok, thats cool, still works too. However sometimes the last folder/window that was open may not be the parent of the current window.
for example I open the “Macintosh HD” then I open “library:macintosh hd:” next I click the “Appications” button in the side strip so that takes me to
“Macintosh HD:Applications:” now when I drag something to the applescript and it moves to “Macintosh HD” instead of “Macintosh HD: Library:”
To get the last folder (as used by the forward & backward buttons in Finder windows in OS X 10.3.x), I suspect you’re going to have to read the Finder prefs file.
I think it is part of the “com.apple.finder.plist” file in the local user’s prefs folder (~/Library/Preferences/com.apple.finder.plist) but that is quite a beast to traverse. Um, I’m not certain why this is so appealing to you. I find it much easier to copy & paste the file into my target location (highlight the file, Command-C, move back via the history button or however you get to the target folder, and hit Command-V) or to use the spring loaded folders to move/copy the file(s).