I'm writing an AppleScript that I'm going to run in a macOS app. This script works fine in Script Editor but when I bring it into Xcode and try to run it, encoding a URL fails with an error about quotation marks.
I'd love any tips to get this to run successfully via Swift and Xcode rather than just Script Editor. Thanks!
My code:
var source = """
on encode(str)
do shell script "php -r 'echo urlencode("" & str & "");'"
end encode
set f to encode("https://twitter.com")
f
"""
let script = NSAppleScript(source: source)!
var error: NSDictionary? = nil
let result = script.executeAndReturnError(&error)
print(result.stringValue)
print(error)
Error prints out:
Optional({
NSAppleScriptErrorBriefMessage = "Expected end of line but found U201c"U201d.";
NSAppleScriptErrorMessage = "Expected end of line but found U201c"U201d.";
NSAppleScriptErrorNumber = "-2741";
NSAppleScriptErrorRange = "NSRange: {60, 1}";
})
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…