Shell commands and Applescript

Discussion in 'Mac Programming' started by Wowzera, Aug 17, 2009.

  1. Wowzera macrumors 6502a

    Joined:
    Oct 14, 2008
    Location:
    Brazil
    #1
    Hello,

    Here goes a piece of my code until now:
    Code:
    display dialog "Please select the two ZIP files"
    			set theFonts to choose file with prompt "Please select the two ZIP files:" of type {"ZIP"} with multiple selections allowed
    			[color=RED][b]duplicate [COLOR="Blue"]theFonts[/COLOR] to fontFolder with replacing[/color][/b]
    The highlighted part is a Finder command to duplicate the files, as you can see. I want to use a do shell script command like this one:

    do shell script "mv theFonts ~/Documents"

    But as expected, it won't work.
    Resuming, is there a way to prompt the user to select files and use the output files on a shell script, by transforming it on a String or something else.

    Thanks for reading anyway. :)
     
  2. angelwatt Moderator emeritus

    angelwatt

    Joined:
    Aug 16, 2005
    Location:
    USA
    #2
    For the shell line I believe you'll want,

    Code:
    do shell script "mv " & theFonts & " ~/Documents"
     
  3. Wowzera thread starter macrumors 6502a

    Joined:
    Oct 14, 2008
    Location:
    Brazil
    #3
    It does not look to work.
    I receive the following output:

    It looks to grab each word and then try to rename :(

    Edit:
    Ok, I got it working. Question solved and answered.
    Thanks.
     
  4. mysterytramp macrumors 65816

    mysterytramp

    Joined:
    Jul 17, 2008
    Location:
    Maryland
    #4
    theFonts is returning a list of Finder file aliases and the shell doesn't understand them. You need to turn them into POSIX pathnames.

    Something like this should work

    Code:
    repeat with f in theFonts
    set fposix to the quoted form of the POSIX path of f
    do shell script "mv " & fposix & " ~/Documents"
    end repeat
    
    mt
     
  5. Wowzera thread starter macrumors 6502a

    Joined:
    Oct 14, 2008
    Location:
    Brazil
    #5
    Hello,
    Thank you so much for sharing this elegant script. But, it does not look to work properly.
    The file does not gets copied and neither return an error or something else. Anyway, I am using cp instead of mv, I want just to get a copy of the file.
    If I do the script in Terminal it looks to work:
    fposix return the correct path, so I use the same path fposix return and do the following:

    Code:
     cp [i]fposix path[/i] ~/Documents 
    It works, but on the applescript shell command, no.

    Could you help me?
    Thanks! :)
     
  6. mysterytramp macrumors 65816

    mysterytramp

    Joined:
    Jul 17, 2008
    Location:
    Maryland
    #6
    This works for me:

    Code:
    display dialog "Please select the two ZIP files"
    set theFonts to choose file with prompt "Please select the two ZIP files:" with multiple selections allowed
    
    repeat with f in theFonts
    	set fposix to the quoted form of the POSIX path of f
    	do shell script "cp " & fposix & " ~/Documents"
    end repeat
    The "of type {"ZIP"}" doesn't work for me. Possibly that particular variation on choose file has been deprecated.

    mt
     
  7. Wowzera thread starter macrumors 6502a

    Joined:
    Oct 14, 2008
    Location:
    Brazil
    #7
    Strange, it works for me (of type {~}). Anyway, I solved the issue, it was my fault, I forget to rename the variable name, everything is correct now,
    Thank you so much for providing this elegant code :)
     

Share This Page