Saving an “Entire Contents” AppleScript to a Variable

Trying to find out why I would get and error and a resolution if possible. If I run in Script Editor it will work but I have to remove the set variable part, it doesn’t matter the application:


tell application "System Events"
   set frontApp to name of first application process whose frontmost is true
end tell

tell application "System Events"
   set frontWindow to the title of window 1 of application process frontApp
end tell

   tell application "System Events"
      get entire contents of window frontWindow of application process frontApp
   end tell
end try

tell application "Keyboard Maestro Engine"
   setvariable "theContents" to the result
end tell

I have also tried using an AppleScript Action in KM and saving to a variable but that seems to slow down my KM at most times. I am also an AppleScript n00b so that could part of the issue. Thanks!

Hey @JD_Faust,

You may want to look at this:

I have a slightly newer version that I'll think about posting as well.

Here's the basics of your problem:

Execute an AppleScript.kmactions (2.2 KB)

Entire Contents can be huge for things like browser windows, so the speed of the macro can vary widely.



Thanks! Ill check it out!