I'm trying to implement an Go2Shell or cd to.. like App and upload it to AppStore. (Put icon on Finder. By pressing the Icon, the user can launch the terminal at the current Finder path)
The classical way to implement it is like the source code here - https://github.com/onmyway133/FinderGo/blob/master/FinderGo/AppWorker.swift. Get the current Finder path by AppleScript return value. And then use /usr/bin/open to launch the terminal with path parameter. This sample project works fine. But if I want to upload it to AppStore, I have to satisfy with the safety law required by Apple.
According to this post ("Executing AppleScript in a Mac app on macOS Mojave and dealing with AppleEvent sandboxing
"), I can't just disable the sandbox or use "temporary exception".
The only possible way is to find the scripting targets of the Finder. But I can't find the corresponding target name by sdef command. Anyone know how to fix this problem?
Sample code:
let currentTrackScript = """
	tell application "Finder"
		set cwd to POSIX path of ((target of front Finder window) as text)
		return cwd
	end tell
	"""
let script = NSAppleScript(source: currentTrackScript)
var errorDict: NSDictionary? = nil
let returnStr = script?.executeAndReturnError(&errorDict).stringValue
if let error = errorDict {
	print(error)
}
print(returnStr)
Error message under sandbox mode:
{
NSAppleScriptErrorAppName = Finder;
NSAppleScriptErrorBriefMessage = "Application isn\U2019t running.";
NSAppleScriptErrorMessage = "Finder got an error: Application isn\U2019t running.";
NSAppleScriptErrorNumber = "-600";
NSAppleScriptErrorRange = "NSRange: {89, 4}";
}
Selecting any option will automatically load the page