Access Finder current path under sandbox mode

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. 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:
Code Block
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:
Code Block
{
    NSAppleScriptErrorAppName = Finder;
    NSAppleScriptErrorBriefMessage = "Application isn\U2019t running.";
    NSAppleScriptErrorMessage = "Finder got an error: Application isn\U2019t running.";
    NSAppleScriptErrorNumber = "-600";
    NSAppleScriptErrorRange = "NSRange: {89, 4}";
}



I'm trying to implement an Go2Shell or cd to.. like App and upload it to AppStore.

Bad idea. Generally speaking, you should consider how your app would work on the iPhone. If that doesn't even make any sense, then your app is probably not suited for the Mac App Store. It probably isn't even suited for the Mac anymore.

Put icon on Finder. By pressing the Icon, the user can launch the terminal at the current Finder path

Yes. I wrote one of the first implementations of such a tool, at least 12 years ago.

The crude way to implement it is like the source code here. Get the current Finder path by AppleScript return value. And then use /usr/bin/open to launch the terminal with path parameter.

Fixed your typo there.

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".

Correct. It is always a bad idea to write software that depends on some other developer's work. You are literally dependent on them. Do they approve of this derived work? Do they support it? Will they change their API one day and break your app? Apple is "some other developer" much like anyone else. They have a certain interest in supporting your work, but they have limits. And since Apple software runs as root, Apple has more limits than other developers.

The only possible way is to find the scripting targets of the Finder. But I can't find the corresponding target name by sdefcommand. Anyone know how to fix this problem?

The limitations you are trying to work around are there by design. This is a case where your success would be considered by Apple to be a critical security bug. Not only will Apple not allow your app in the Store, they will literally submit an update to the operating systems of 100 million devices just to block your app.

The easy answer is to just find some other app to work on. Apple has a number of authorized Finder APIs you could use if you really wanted to. However, most of the limitations I mentioned above would still apply. It is better to go your own way, write an app that people want to use, and then add support for operating system integration as you have time, in a secondary capacity. There is literally no possible downside to this approach.
Access Finder current path under sandbox mode
 
 
Q