Is there something obviously wrong with the AppleScript included in a macro?

Hello, I am writing a palette for the Simple Mind MindMap app some of which require scripting.

KM Engine error message
AppleScript failed with script error: text-script:21:30: script error: A “"” can’t go after this identifier. (-2740)

activate application process "SimpleMind Pro"
tell application "System Events"
tell process "SimpleMind Pro"
click button 1 of group 1 of group 1 of splitter group 1 of window "content.smmx"  of application process "SimpleMind Pro"
end tell
end tell

thanks in advance for your time and help

It looks like you need to wrap the tell application process line with tell application "System Events" like yo do further down.

The following works for me (at least in the sense that it lets me compile the script):

tell application "System Events"
	tell application process "SimpleMind Pro" to activate
	tell process "SimpleMind Pro"
		click button 1 of group 1 of group 1 of splitter group 1 of window "content.smmx" of application process "SimpleMind Pro"
	end tell
end tell

I don’t have that app to test with, but I imagine you could even shorten the script more so, like this:

tell application "System Events"
	tell process "SimpleMind Pro"
		activate
		click button 1 of group 1 of group 1 of splitter group 1 of window "content.smmx" of application process "SimpleMind Pro"
	end tell
end tell

-Chris

1 Like

thank you for thinking about my problem.

both scripts failed. KM Engine log for each attempt

2023-01-30 17:21:07 Action 12935453 failed: Execute an AppleScript failed with script error: text-script:117:243: execution error: System Events got an error: Can’t get application process "SimpleMind Pro" of process "SimpleMind Pro". (-1728)

2023-01-30 17:21:07 Execute an AppleScript failed with script error: text-script:117:243: execution error: System Events got an error: Can’t get application process "SimpleMind Pro" of process "SimpleMind Pro". (-1728). Macro “Add as Style Preset” cancelled (while executing Execute AppleScript).

Those last four tokens in the main expression:

...of application process "SimpleMind Pro"

look redundant (the line is already wrapped in tell ...)

I would start by simply deleting them.

Thanks very much. Works perfectly now. I changed the name of the window to window 1, which works fine.

The only funny thing is that when I open a secondary window called Apply Style Preset with the script, the SimpleMind dock icon bounces a few times until I click on the canvas, which it does not if I click on the corresponding icon. How would you interpret that ?

To get the initial script, I used UI Browser which is tedious because it is buggy.

  • If I see a clickable icon on my screen (not a button) with an assigned name, for example Apply Style Preset, is there any way to create a script based on that knowledge alone, and knowing that I am working in the front window 1. I am asking because this is a common and recurrent issue.

Thanks very very much for solving my problem.

2023-01-31_06-11-22

You can't activate an application process – you'll end up activating System Events instead of the process.

tell application "SimpleMind Pro" to activate

tell application "System Events"
   tell application process "SimpleMind Pro"
      click button 1 of group 1 of group 1 of splitter group 1 of window "content.smmx"
   end tell
end tell

If the process is running you can use its frontmost property to bring it to the front.

tell application "System Events"
   tell application process "SimpleMind Pro"
      set its frontmost to true
   end tell
end tell
1 Like

In a word – no.

There's no telling where in the object hierarchy the icon will be, nor can you be absolutely certain what kind of object it will be.

You have to go fishing...

Here I'm looking for buttons at the top level of the front window:

tell application "System Events"
   tell application process "TextEdit"
      tell its front window
         buttons
      end tell
   end tell
end tell

Here I'm looking more broadly:

tell application "System Events"
   tell application process "TextEdit"
      tell its front window
         
         set diagnosticsList to {¬
            "----- PROPERTIES -----", ¬
            properties, ¬
            "----- UI ELEMENTS -----", ¬
            UI elements, ¬
            "----- ATTRIBUTES -----", ¬
            attributes, ¬
            "----- ACTIONS -----", ¬
            actions, ¬
            "----- END -----"}
         
      end tell
   end tell
end tell

Is there any way to send the results to the clipboard?

Thank you!

Use my macro:

1 Like

Great, thanks.