Scripting Help!

Discussion in 'macOS' started by G99, Mar 25, 2006.

  1. G99 macrumors 6502

    G99

    Joined:
    Mar 8, 2006
    #1
    After I realised how easy it was for me to download a UNIX executable, or an application without knowing it, and launching it, I started work on a script that showed the information window of a new downloaded item. I plan on saving the script as a folder action, and attaching it to my desktop (my default downloads file). So far I have managed:

    on adding folder items to this_folder after receiving these_items
    tell application "Finder"
    display dialog "Would you like to open the information window of your downloaded items?" buttons {"Yes", "No"} default button 1
    if the button returned of the result is "Yes" then
    open information window of ?
    end if
    end tell
    end adding folder items to

    Can someone please edit the question mark on the 6th line, because I'm not too sure on what to do here. Sorry about the simpleness of my problem-scripting is a completely self-taught subject for me.
     
  2. HexMonkey Administrator

    HexMonkey

    Staff Member

    Joined:
    Feb 5, 2004
    Location:
    New Zealand
    #2
    You can use a repeat statement to loop through the items in a list, as follows:

    Code:
    on adding folder items to this_folder after receiving these_items
    	tell application "Finder"
    		display dialog "Would you like to open the information window of your downloaded items?" buttons {"Yes", "No"} default button 1
    		if the button returned of the result is "Yes" then
    			repeat with new_item in these_items
    				open information window of new_item
    			end repeat
    		end if
    	end tell
    end adding folder items to
     
  3. G99 thread starter macrumors 6502

    G99

    Joined:
    Mar 8, 2006
    #3
    Thank you for your reply!
    But, I've run into another problem..
    When I attach the folder action to the desktop, and add a new file to it, nothing happens. What have I done wrong?
     
  4. HexMonkey Administrator

    HexMonkey

    Staff Member

    Joined:
    Feb 5, 2004
    Location:
    New Zealand
    #4
    It should work, try creating it again using the following steps:

    1. First remove the existing folder action by right/control clicking on the Desktop and choosing "Remove a Folder Action > [Your script name]"
    2. In Script Editor, save your script using the Script file format, and save it in /Library/Scripts/Folder Action Scripts/
    3. Right/control click on the Desktop and choose "Attach a Folder Action..."
    4. Navigate to and choose your saved script
    5. Save/move/download a file to the Desktop to test if it works
    Also make sure that folder actions are enabled by checking that there's an item in the Finder contextual menu that says "Disable Folder Actions" rather than "Enable Folder Actions".
     
  5. G99 thread starter macrumors 6502

    G99

    Joined:
    Mar 8, 2006
    #5
    Thank you for your help. I didn't realise you had to save the script in Folder Action scripts. The script now works perfectly. Thank you very much.
     

Share This Page