I am using information from the post at https://developer.apple.com/forums/thread/98830
Hi, I am using the example from the above forum post in my Swift app and it's working perfectly however pre-compiling the app is causing me an issue. My script is checking if an app existing using Finder and does this before doing other tasks but for some reason. when my app first runs and the script compiles, it is looking for the app and prompting the user to choose it. Any subsequent script calls work as expected.
let script = NSAppleScript(source: """
on lazyPasteRDP()
try
tell application "Finder" to get displayed name of application file id "com.microsoft.rdc.macos"
set appExists to true
on error
set appExists to false
end try
if appExists
tell application "System Events"
set activeApp to name of first application process whose frontmost is true
if "Microsoft Remote Desktop" is in activeApp then
tell application "myApplication"
activate
end tell
tell application "Microsoft Remote Desktop"
activate
delay 0.5
tell application "System Events" to keystroke "v" using control down
end tell
else
tell application "System Events" to keystroke "v" using command down
end if
end tell
else
tell application "System Events" to keystroke "v" using command down
end if
end lazyPasteRDP
"""
)!
Is there a way to prevent prompting the user to choose the app during compile time? Again, once the script is compiled, the logic works as expected and doesn't prompt again. The other option would be to only compile the script on a condition but my feeble attempts haven't worked. I tried to post a comment in the original thread but couldn't get enough detail in the 500 character limit