How to position the KM's “Icon Chooser: Character” floating window

Hi Chris,

first: yes, you’re right … I forgot about my successful 2014-topic … sorry for that :wink:

second: thanks a lot for your help and offer!
I would like to position the KM’s “Icon Chooser: Character” floating window and didn’t get via AppleScript / System Events so far. So if you can get it without putting too much effort into it it would be nice …

Thanks and have a nice day
Larry

Hey Larry,

If you're trying to get properties of a floating window from the Script Editor.app or Script Debugger, you need to take into account that these often disappear when their application is in the background.

The easiest way to deal with that is to use set frontmost to true like so:

tell application "System Events"
   tell application process "Keyboard Maestro"
      set frontmost to true
      properties of windows
   end tell
end tell

Then return to your Applescript Editor and examine the result:

tell application "System Events"
   tell application process "Keyboard Maestro"
      tell (first window whose name is "Icon Chooser: Internal")
         set position to {1540, 23}
      end tell
   end tell
end tell

On the other hand the technique I use is to run a script in Script Debugger from another script.

So – I'd take the first script and remove the set frontmost to true line.

Then I'd use another script with a global keyboard shortcut to run it.

tell application "Script Debugger"
   tell document 1
      execute
   end tell
end tell

This lets me run complicated scripts that need an app to be frontmost and have results returned in the editor (without having to switch between Script Debugger and the app).

-Chris

2 Likes

Let me be sure I understand this:

  • You set up a KM macro with a hotkey.
  • When triggered, this macro tells Script Debugger to execute whatever script is in Script Debugger’s “document 1”.

To use this, you:

  • Go to the application you want your Script Debugger script to automate.
  • Trigger the aforementioned macro.
  • Since the target application is already “activated”, all the Script Debugger script needs to do is, well, execute.

Have I got this correct? This incredibly obvious, yet never-crossed-my-mind-before technique? Holy crap, you’re good!

Do me a favor the next time you’re in Southern California. Come over to my house and watch me work for awhile. Look over my shoulder, and when you see something that could be done in an easier way, say “You know, you could…”

In all seriousness, if I wasn’t retired, I’d consider finding a way to pay for you to come over and spend a day doing just that. Then take you to Disneyland the next day, since I have lifetime free passes. :slight_smile:

Of course, I wouldn’t get any work done because we’d be talking all the time, but the amount of good stuff I could glean from you would be almost priceless.

1 Like

Hey Dan,

You grok.

Obvious in hindsight.

It was years and years before I thought of doing this.

I was working on a sticky problem that needed an app frontmost, and I got utterly sick of having to switch back and forth.

What I did was set things up so I could see the Script Debugger result panel in the background. That way I could change things in the front app and run the script in Script Debugger without having to switch at all.

It was one of those V8 moments.  :bulb:

-Chris

Yes, I'm old enough to remember that. :slight_smile:

When I saw the notification I thought you meant grok:sunglasses:

1 Like

Hi Chris,

Thanks a lot!
I adapted your lines as shown below.

For anyone being interested: The purpose of this script (in combination with positioning the editor window) is – of course – to reset the windows to a once defined basic window layout.

Your hint regarding Script Debugger:
I help myself by having the target app in front and the script in Script-Editor in the background but with it’s play button visible/clickable. Then I click on the play button while pressing the command key. But I think you know this option for sure.

So have a nice day
Claus


AppleScript:


property pal_IconChooser : {907, 23}
property pal_color : {948, 282}

tell application "System Events"
   tell application process "Keyboard Maestro"
      set frontmost to true
      try
         set position of (first window whose name contains "Icon Chooser") to pal_IconChooser
      end try
      try
         set position of (first window whose name contains "Color") to pal_color
      end try
   end tell
end tell

Hey Claus,

That works.

You can also do this from a macro:

tell application "Script Editor"
   execute document 1
end tell

-Chris