Automator script help

Discussion in 'Mac Programming' started by tooobe, Jan 16, 2017.

  1. tooobe, Jan 16, 2017
    Last edited: Jan 16, 2017

    tooobe macrumors regular

    Joined:
    Nov 3, 2008
    #1
    Hello,

    I made a "app" in Automator which takes the path and name of the file I have highlighted in Finder, opens Terminal, opens the path and runs a script on the file. It works great except when there is a space in the path to the file, then stops it (and run the folder named as the first part without spaces, if the folder exists - for example, I want to open the path "Hello to you", it opens the folder "Hello" if available.

    Here is the relevant part of my Automator script:
    tell application "Terminal"
    Activate
    if not (exists window 1) then reopen
    end tell

    tell application "System Events"
    keystroke "t" using command down
    keystroke "cd \""
    keystroke "v" using command down
    return keystroke

    I have tried, as you see with \" to insert quotation marks as characters (to get an absolute path) according to the instructions at https://developer.apple.com/library...leScriptLangGuide/reference/ASLR_classes.html but it does not seem to work anyway. Even tried writing quote as suggested as an option on the apple page. Some other sites mentioned "& quote &" as an option, but not working either. Also tried to add key code 39 (which should correspond to quote symbol) on a new line, but also not working. If I use terminal history and add quotation marks before and after the path, everything works perfectly, and that's why I have focused on trying to get the quotes automatically :)

    Someone who is awesome with Automator / AppleScript that can help me? :)
     
  2. Red Menace macrumors 6502

    Red Menace

    Joined:
    May 29, 2011
    Location:
    Littleton, Colorado, USA
    #2
    You also need a closing quote, for example:
    Code:
        keystroke "cd " & quote
        keystroke "v" using command down
        keystroke quote & return
    
     
  3. tooobe thread starter macrumors regular

    Joined:
    Nov 3, 2008
    #3
    Thanks a million, that works!
     

Share This Page