How to run AppleScript in macOS

Issue #223 Surround script by single quotes let script = """ tell application "XcodeWay" activate end tell """ let command = "osascript -e '\(script)'" let process = Process() process.launchPath = "/bin/bash" process.arguments = ["-c", command] Run as administrator In terminal, we can cd ~/Library sudo mkdir MyNewFolder In code, we use with administrator privileges, this when run will ask for password or fingerprint do shell script "mkdir MyNewFolder" with administrator privileges ...

May 2, 2019 · 1 min · Khoa Pham

String manipulation in Apple Script

Issue #89 Today I find that AppleScript allows us to import Foundation, with that we have lots of power, including NSString. See my script use scripting additions use framework "Foundation" property NSString : a reference to current application's NSString Here is how I can remove last path component from a string on myRemoveLastPath(myPath) set myString to NSString's stringWithString:myPath set removedLastPathString to myString's stringByDeletingLastPathComponent removedLastPathString as text end myRemoveLastPath You need to cast to NSString with NSString's stringWithString: and cast back to Apple Script string with as text....

October 18, 2017 · 1 min · Khoa Pham

How to call function inside Apple Script

Issue #88 I ’ve been using Apple Script to for my Finder extension FinderGo. Because of sandboxing, all scripts must lie inside Application Scripts folder. Today, I was rewriting my Xcode extension XcodeWay. Before Xcode 8, we could use Xcode plugin and all kinds of magic to make our dreams come true https://github.com/onmyway133/XcodeWay/blob/1.0/XcodeWay/Helper/FTGEnvironmentManager.m#L50. But then it does not work since Xcode Source Editor Extension was introduced. So I rewrote XcodeWay as an extension https://github....

October 18, 2017 · 2 min · Khoa Pham