0

Is there a way to tell if my application was activated by AppleScript?

ie, I have the following AppleScript

tell application "MyApp"
  activate
end tell

Is there a way I can tell it was AppleScript and not a User manually clicking on the app to activate it?

//func applicationDidBecomeActive(_ notification: Notification)
//or
func applicationDidFinishLaunching(_ aNotification: Notification) {
  switch someLaunchMethod {
    case .click:
      print("user clicked")
    case .applescript:
      print("activated from AppleScript")
  }
}
Chris
  • 11
  • 4
  • No, there isn't. – vadian Sep 27 '22 at 13:16
  • The script calls the delegate method the same as clicking on the app - what exactly are you tying to do? – red_menace Sep 27 '22 at 14:32
  • It's for Analytics, how many users are scripting my app – Chris Sep 27 '22 at 14:44
  • I don’t use Swift, but one option would be to check if the application sending the AppleEvent is not the Finder or Dock. – red_menace Sep 27 '22 at 17:08
  • @red_menace Do you have an example of that in another language? – Chris Sep 28 '22 at 13:08
  • You can use something similar to the answer for https://stackoverflow.com/questions/57064023 - the idea is to get the bundle identifier for the app sending a (re)open AppleEvent, and if it is not the Finder or Dock (or itself), it would most likely be from a script. – red_menace Sep 28 '22 at 15:09

0 Answers0