Can you execute an Applescript script from a Swift Application

前端 未结 6 1589
野的像风
野的像风 2020-12-01 01:25

I have a simple AppleScript that sends an email. How can I call it from within a Swift application?

(I wasn\'t able to find the answer via Google.)

6条回答
  •  孤街浪徒
    2020-12-01 02:01

    You can try NSAppleScript, from Apple's Technical Note TN2084 Using AppleScript Scripts in Cocoa Applications https://developer.apple.com/library/mac/technotes/tn2084/_index.html

    NSAppleScript* scriptObject = [[NSAppleScript alloc] initWithSource:
                @"\
                set app_path to path to me\n\
                tell application \"System Events\"\n\
                if \"AddLoginItem\" is not in (name of every login item) then\n\
                make login item at end with properties {hidden:false, path:app_path}\n\
                end if\n\
                end tell"];
    
    returnDescriptor = [scriptObject executeAndReturnError: &errorDict];
    

提交回复
热议问题