简体   繁体   中英

Apple Script folder action not working: Need to change file extension

I'm kind of a beginner at this, so hopefully this is a simple problem:

I'm trying to create a folder action that will change a file with extension ".jpeg" to ".jpg" when it's put in a given folder.

I set up a folder action to do this, but it's not doing anything for some reason.

here's my script:

on adding folder items to this_folder after receiving added_items
    display dialog "hello" as text --> Does not display anything
    repeat with theItem in the added_items
        tell application "Finder"
            set n to name extension of theItem
            if n = "jpeg" then
                set name extension of theItem to "jpg"
            end if
        end tell
    end repeat
end adding folder items to

Any guesses?

Check that folder actions are globally enabled:

Run application Folder Actions Setup ( /System/Library/CoreServices/Folder Actions Setup.app ) and ensure that Enable Folder Actions is checked.

Check to make sure that your specific script is installed as a folder action:

In the same application:

  • Does the target folder show up in the list on the left?
  • If it does and you select it, is your script listed in the list on the right?

Note that folder-action scripts must be saved in one of 2 locations:

  • /Library/Scripts/Folder Action Scripts (machine-wide)
  • ~/Library/Scripts/Folder Action Scripts (user-specific)

Also note that you can alternatively use Automator to create folder actions, but only for files being added (not removed) - this would allow you to use a language other than AppleScript, if desired.

Note, however, that neither mechanism allows you to react to files getting modified .

Incidentally, your debug alert could be written more simply as:

display alert "hello"

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM