Macros (Execute Applescript) working/not working

Hi,

I don’t know if this is the right forum, since this is more Applescript-related, but anyway;

Some of my Macros, based on Applescript involving the Finder, works sometimes but not always.

Here’s a simple example:

tell application "Finder"
    set bounds of front window to {10, 50, 1275, 1000}
end tell

I’m no script expert, basically using snippets and copy/paste with trial and error.

Any clues?

I’m on OS X 10.9, but soon on 10.10

What version of Keyboard Maestro are you using?
Ver 7 requires Yosemite (10.10.3)+

KM has lots of great Actions that deal with windows. You might take a look at:
Manipulate a Window Action

Hey Haken,

Run it with an error-handler, so you can see if/when the script throws an error.

-Chris

try
  
  tell application "Finder"
    set bounds of front window to {10, 50, 1275, 1000}
  end tell
  
on error e number n
  set e to e & return & return & "Num: " & n
  if n ≠ -128 then
    try
      tell application (path to frontmost application as text) to set ddButton to button returned of ¬
        (display dialog e with title "ERROR!" buttons {"Copy Error Message", "Cancel", "OK"} ¬
          default button "OK" giving up after 30)
      if ddButton = "Copy Error Message" then set the clipboard to e
    end try
  end if
end try
1 Like

Thank you, ccstone and JMichaelTX!

I’ve upgraded to 10.10.5 and KM 7.0.3 since my OP.
Tried your error handler, Chris, and got an error; ”10000”.
Weird that it sometimes works, but I’m gonna use the KM actions for windows instead.

First I suspected XtraFinder, since it makes the Window Switcher see dupes of Finder windows.
This might be for another thread, but I only use XtraFinder for a couple of things, like automatically adjusting the width of Columns etc, but if it confuses KM and others I think I have to stop using it.

Back to the subject:
The script below behaved like my window position script - it work from time to time.

tell application "Finder" to select (every file of window 1 whose name extension is "ptx")

When I changed it to the following it seems to work all the time:

try
    tell application "Finder" to set currentDirectory to target of Finder window 1
end try
tell application "Finder" to select (every file of currentDirectory whose name extension is "ptx")

Hey Haken,

There’s your problem.

XtraFinder plays a bunch of games with the FInder’s interface and causes problems when using AppleScript to address windows.

I quit using TotalFinder years ago because of similar issues.

-Chris

FYI, I’ve been using TotalFinder for over a year now, and have not noticed any issues. I’m running Yosemite (10.10.5). Maybe they have fixed the issue saw earlier.

Hey JM,

There were multiple problems, but you’re right they might have been fixed since I last installed TotalFinder (several years now).

Unfortunately it’s not worth my time to find out, especially since El Capitan breaks TotalFinder (unless you turn off System Integrity Protection aka SIP).

-Chris