How to Enable/Disable Folder Options Using AppleScript?

Discussion in 'Mac Programming' started by Isw, Dec 28, 2007.

  1. Isw macrumors newbie

    Joined:
    Dec 27, 2007
    #1
    Hi,

    Im Newbie to apple scripting.How should i set "Enable Folder Options" or "Disable Folder Options" using applescript?
    I used the following code, but the folder action is not enabled to the specified folder:

    tell application "System Events" to set enabled of folder action "some folder" to true

    Where am i going wrong. Please help.

    Thanks in Advance
     
  2. HiRez macrumors 603

    HiRez

    Joined:
    Jan 6, 2004
    Location:
    Western US
    #2
    I'm a little confused, since you said both folder options and folder actions in your post, but I think you mean actions.

    If you want to globally enable/disable actions, then try
    Code:
    tell application "System Events" to set folder actions enabled to true
    But, I don't think that can target a single folder. You can script the application Applications/AppleScript/Folder Actions Setup to do this, however this application only became scriptable in 10.5 Leopard. I don't know how you'd do it on pre-10.5 systems. Have a look at the scripts that came with your system, in /Library/Scripts/Folder Actions (under the root dir, not your home folder), and you weill see some examples. Try the one called "Remove Folder Actions.scpt". It's a kind of long-winded and klunky way to go about it, but you might be able to get some ideas that way.

    Click this link for details on the 10.5 mechanism.
     
  3. Isw thread starter macrumors newbie

    Joined:
    Dec 27, 2007
    #3
    Sample script to make Folder Action Setup Scriptable

    Hi,

    Thanks for ur reply.can u give any sample applescript's for making the Folder Action Setup Application Scriptable?
    This will be very helpful.

    Thanks
    Isw


     
  4. HiRez macrumors 603

    HiRez

    Joined:
    Jan 6, 2004
    Location:
    Western US
    #4
    Sorry, I can't since that application just recently became scriptable with Leopard (which I don't even have yet). Be on the cutting edge! You might try asking on the MacScripter site.
     
  5. buzzwig macrumors newbie

    Joined:
    Jun 4, 2008
    #5
    Disable/enable folder actions 10.4

    Here's how I got around the limited scriptability of Folder Actions Setup using UI scripting which requires the "Enable access for assistive devices" box to be checked in Universal Access control panel. I use this on login so that all my folder actions are always active when I'm logged in as me. First I have to disable all folder actions because the system sometimes gets confused and sticks an an infinite loop if I don't. Then I add the actions I want...


    -- removing all actions...

    tell application "Folder Actions Setup"
    activate
    end tell
    tell application "System Events"
    tell process "Folder Actions Setup"
    delay 0.2
    key code 0 using command down -- command - a (select all)
    delay 0.2
    click button "-" of splitter group 1 of window "Folder Actions Setup"
    set frontmost to true -- the focus is sometimes lost...
    if exists button "OK" of sheet 1 of window "Folder Actions Setup" then
    set frontmost to true
    click button "OK" of sheet 1 of window "Folder Actions Setup"
    delay 0.3
    end if
    end tell
    end tell
    tell application "Folder Actions Setup" to quit

    -- add the actions...

    tell application "System Events"
    try
    attach action to folder "pathtothefolder:thefolder:" using "youractionscript.scpt"
    end try
    end tell

    ~buzzwig
     
  6. buzzwig macrumors newbie

    Joined:
    Jun 4, 2008
    #6
    Better yet...

    -- remove existing actions...

    tell application "System Events" to ¬
    set FolderActionNames to name of every folder action

    if FolderActionNames is not {} then
    repeat with EachFolder in FolderActionNames
    tell application "System Events" to ¬
    delete folder action EachFolder
    end repeat
    end if

    -- add the actions...

    tell application "System Events"
    try
    attach action to folder "pathtothefolder:thefolder:" using "youractionscript.scpt"
    end try
    end tell

    ~buzzwig
     

Share This Page