single quote escaping in applescript/shell

后端 未结 3 878
无人共我
无人共我 2021-02-10 08:35

I\'m trying to process this shell script in applescript, but it keeps saying error EOF, because of the single quote in the folder name.

do shell script \"cp -R \         


        
3条回答
  •  有刺的猬
    2021-02-10 09:03

    Adding an answer for JavaScript for AppleScript (JAX) users based on answer from McUsr:

    debugger
    
    var app = Application.currentApplication();
    app.includeStandardAdditions = true;
    
    var source = "/documents/John's Spreadsheet.xls";
    var target = "/documents/John's Spreadsheet.csv";
    
    source = source.replace("'", "'\"'\"'", "g");
    target = target.replace("'", "'\"'\"'", "g");
    
    var exportScript = "/excel -i";
    exportScript += " '" + source + "'";
    exportScript += " '" + target + "'";
    exportScript += ";true";
    
    try {
        app.doShellScript(exportScript);
    }
    catch (error) {
        console.log(error.message);
    }
    

    If you don't know what JAX is it's AppleScript but using JavaScript. Open Script Editor and select JavaScript from the dropdown beneath the record button.

提交回复
热议问题