Yesterday, I mentioned the Favorites folder. And, while you could use it to store aliases (like your supposed to), why not use it as a on demand filing service. What I mean, is you set it up so that you can select a file -say, a script- and then, you hit Cmd-Shift-T. This will send the file away to your applescripts folder conveniently located at ~/Documents/AppleScripts/.
Here's how to do that.
Step 1: Create the applescript.
The code for the applescript is:on adding folder items to theFolder after receiving theItems
repeat with i in theItems
set duplicated to "not"
tell application "Finder"
set theoriginal to the original item of i
set itemname to the name of theoriginal
if itemname contains ".png" then
if duplicated is equal to "not" then
set theduplicate to duplicate theoriginal to (":Users:oliver:Pictures:" as alias)
set duplicated to "yes"
else
make new alias to theduplicate at (":Users:oliver:Pictures:" as alias)
end if
end if
delete i
if duplicated is "yes" then
delete theoriginal
else
display dialog "No action taken on the item"
end if
end tell
end repeat
end adding folder items to
You can download the applescript here.
Step 2: Customize the applescript.
This part is pretty easy. What you want to do, is figure out where you want to move the items to. Because of the design of the script, all you have to do is add 3 lines that say:
if itemname contains "something" then
if duplicated is equal to "not" then
set theduplicate to duplicate theoriginal to (":Path:To:folder:" as alias)
set duplicated to "yes"
else
make new alias to theduplicate at (":Path:To:folder:" as alias)
end if
end if
Now, replace "something" with what you want the item name to contain. So, if you name all the files in your work project with "work" in the name (ie: workpresentation.key), you might want to setup a folder in your Documents folder called "Work". Then, use: if itemname contains "work" then
if duplicated is equal to "not" then
set theduplicate to duplicate theoriginal to (":Users:oliver:Documents:Work:" as alias)
set duplicated to "yes"
else
make new alias to theduplicate at (":Users:oliver:Documents:Work:" as alias)
end if
end if
to move the stuff there. Just be sure to replace the path I've supplied with the real path!
Step 3: Apply the AppleScript.
This is one of the things that messed me up. When applying an applescript to a folder action, you HAVE to use the folder actions dialog. So, to add our folder action, we'll need to move it to /Library/Scripts/Folder Action Scripts/. Then, go to ~/Library/Favorites/ and right click on the folder. Select "Configure Folder Actions..." from the "More" sub-menu.
In the window that pops up, click on the plus sign for the left-hand column and select ~/Library/Favorites/. Then, select the folder action script we made earlier.
Step 4: Application
Now that we have it all set up, we can test it out. Select a file in Finder that you defined in the script and hit Cmd-Shift-T. After a couple of seconds, the file should disappear and be in the folder you destined it to. If it doens't do anything, go to the applescript we wrote and edit it so that it works. While you're working on it, you can save it and test it out without having to reattach it to the folder.
For those of you reading this through RSS, there is a youtube video embedded in the post. You can watch it here.
Well, that's all for now! Tomorrow is the 1 year anniversary of the MacTipper Blog, but, because we don't do posts on Saturday, there will be two posts on sunday! Tip you then!
Update: I've changed teh applescript dramatically. So, if you have an item that fits under multiple items, then it will move the original to the first place, and then alias the new file to the other places.
1/25/08
Updated: Using the Favorites Folder as an On-Demand Auto-Filer
Posted by
MacTipper
at
Friday, January 25, 2008
Labels: AppleScript
Subscribe to:
Post Comments (Atom)


0 comments:
Post a Comment