Need help with apple script do shell command.

Discussion in 'Mac Programming' started by coo1man1, Aug 25, 2009.

  1. coo1man1 macrumors newbie

    Joined:
    Aug 25, 2009
    #1
    Hi,
    I rlly need help iwth this command...

    i have:
    Code:
    do shell script "cd /Users/henry/stuff/"
    But i do not know where that file would be on someone else's computer. Is there a command that can have then drag the file in a text field or put in where it is?

    Thanks,
    Henry:apple:
     
  2. HiRez macrumors 603

    HiRez

    Joined:
    Jan 6, 2004
    Location:
    Western US
    #2
    You can use the choose folder command to bring up a file chooser dialog.
     
  3. mysterytramp macrumors 65816

    mysterytramp

    Joined:
    Jul 17, 2008
    Location:
    Maryland
    #3
    You can also do this with many/most/several do shell scripts:

    Code:
    set aRandomVar to do shell script "ls /Users/"
    
    aRandomVar will give you the list of files in the directory from the script.

    it doesn't always work or capture errors. For example, if you use:

    Code:
    set aRandomVar to do shell script "cd /Us"
    
    Applescript posts an error, but you haven't trapped it so your script halts. A try block works, however:

    Code:
    try
    	do shell script "cd /Us"
    on error errMsg number errNum
    	-- you can include code based on the error if you want.
    end try
    
    errMsg returns: "sh: line 0: cd: /Us: No such file or directory"

    mt
     

Share This Page