Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!


try this | 16 comments | Create New Account
Click here to return to the 'try this' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
try this
Authored by: adrick42 on Oct 30, '03 09:58:49PM

I tried to write something like this but couldn't get it to work.

---
cd ~/ ; %20out



[ Reply to This | # ]
try this
Authored by: Graff on Oct 30, '03 11:35:28PM

I just tested all of the modifications listed above and here is a script that works fine:

on adding folder items to this_folder after receiving added_items
  tell application "Finder"
    set homeFolder to (container of (path to desktop folder) as string)
    set folderLocation to homeFolder & "Pictures:unfiled:"
    repeat with aFile in added_items
      if the name extension of aFile is in 
        {"jpg", "gif", "png", "pict", "tiff", "gif", "psd", "bmp"} then
        tell application "Finder"
          try
            move aFile to folder folderLocation
          on error err
            display dialog err
          end try
        end tell
      end if
    end repeat
    display dialog 
      "Image files have been moved to the Unfiled" & return & 
      "folder in your Pictures folder."
  end tell
end adding folder items to

If this doesn't work for you then make sure that you have run the "Enable Folder Actions" script and have successfully attached a folder action to the folder you want this script to run from. For a good reference on how to get it all to work see Apple's web page on Folder Actions.



[ Reply to This | # ]
try this
Authored by: Shippley on Oct 19, '05 08:23:30PM
I moved the dialoge box telling me that image files had been moved because it was saying it no matter what I added..
on adding folder items to this_folder after receiving added_items
	tell application "Finder"
		set homeFolder to (container of (path to desktop folder) as string)
		set folderLocation to homeFolder & "Pictures:unfiled:"
		repeat with aFile in added_items
			if the name extension of aFile is in 
				{"jpg", "gif", "png", "pict", "tiff", "gif", "psd", "bmp"} then
				tell application "Finder"
					try
						move aFile to folder folderLocation
					on error err
						display dialog err
					end try
					display dialog 
						"Image files have been moved to the Unfiled" & return & 
						"folder in your Pictures folder."
				end tell
			end if
		end repeat
	end tell
end adding folder items to


[ Reply to This | # ]
try this
Authored by: Graff on Oct 31, '03 12:07:49AM

Heh, whups. I thought you meant that you couldn't get my modifications to work. I see now that you were just saying that you had problems with writing something similar to what I used.

The key difference between these this statement:

if the name of aFile contains {".jpg"} then

and this one:

if the name extension of aFile is in {"jpg", "gif", "png"} then

are the keywords contains and is in.

When you use the keyword contains with a list it wants to match ALL of the items in the list (a logical AND), so if you did:

if the name of aFile contains {".jpg", ".gif", ".png"} then

The only thing that would match would be a file named "myfile.jpg.gif.png", or any file with all of those somewhere in it.

The keyword is in gives a match if one or more of the items in the list match (a logical OR). Since you are looking for a .jpg OR a .png OR a .gif and so on, this is what you want to use.

I also used name extension since that strips off all the file name except for the extension (even the dot). You have to do this because is in looks for exactly that item in the list. If I didn't do this then an item named "myfile.jpg" wouldn't be found in the list {"jpg, "png", "gif"}. However just "jpg" would be found in that list.

For a file like myfile.jpg.zip it gets more complicated. Basically then I would use the text item delimiters statement to chunk out all the stuff seperated by dots and then compare to those. You can read about how to do that in this MacCentral AppleScript Primer article, but it's probably not worth doing.



[ Reply to This | # ]