Launch files from, to and testing?

I was trying a macro to launch files in from PathFinder with BBEdit, I was basing this on the help I received in a previous post. Something is not correct. So in pursuit of understanding I have the question; how could you get a report of what the variables equal after the first end tell? The second question is where did I go wrong with this. Thanks

Hey Chris,

In general one should always test AppleScript in the Script Editor.app before running it from Keyboard Maestro. It provides more tools for examining your results.

Firstly:

Your script is trying to get text item 2 of each posix path. You don’t want to do that; you want the full path.

Secondly:

You don’t need a loop to open the listed items in BBEdit. BBEdit will accept a list of posix paths as input, as you can see below.

------------------------------------------------------------
# Auth: Christopher Stone <scriptmeister@thestoneforge.com>
# dCre: 2015/11/11 02:20
# dMod: 2015/11/11 02:26
# Appl: Path Finder & BBEdit
# Task: Open Selected items in Path Finder in BBEdit.
# Libs: None
# Osax: None
# Tags: @Applescript, @Script, @BBEdit, @Path_Finder, @Open, @Selection
------------------------------------------------------------

tell application "Path Finder"
  set pfSelectionList to selection
  if pfSelectionList ≠ missing value then
    repeat with i in pfSelectionList
      set (contents of i) to POSIX path of (contents of i)
    end repeat
  else
    error "Nothing is selected in Path Finder!"
  end if
end tell

# Uncomment the next line to see the contents of variable 'pfSelectionList'.
# return pfSelectionList

tell application "BBEdit"
  activate
  open pfSelectionList
end tell

------------------------------------------------------------

Note the commented-out line of code.

return will stop execution and return the designated item.

Valid comment characters are:

# <your code or comment>
-- <your code or comment>
(* <your code or comment> *)

Obviously comment characters can be used to embed comments in your code.

Less obviously they can be used to comment-out sections of code to control the execution and output.

In Keyboard Maestro you can have the Execute an AppleScript action display the result in a window.

Unfortunately AppleScript List and Record Objects get coerced to text under those circumstances, so a person unfamiliar with what they’re looking at may be confused.

The output in the Script Editor.app is more accurately depicted – easier to understand – and easier to work with. So to repeat myself – get things running correctly in the Script Editor.app and then move the code to Keyboard Maestro.

There are many vids on YouTube that show how to use the Script Editor.app (Applescript Editor.app in OSX versions previous to Yosemite).

Anyone who writes scripts professionally or a serious amateur will want to scope out Script Debugger as well. (Although the $199 U.S. price tag scares off most folks – who never learn what they’re missing.)

-Chris

This is a wealth of information. I did not know about the Script Editor.app, I had sought out a couple of Apple Script training titles I want to want to watch. I see there is a trail for the Script Debugger app to try it out, it looks great. As for the script it does just what I want!
I had played around with the dropdown for (e.g. Ignore results, display results in window, … ), I don’t know if this made things change but the first time I pasted the working script in the window it did not function. I had changed it back to “Ignore results”, but it would not work. I created a fresh script and it was fine. Is there more to this dropdown that meets the eye? Maybe I just missed something else, but no real big deal. Thanks you so much for all the help, like I said this is a wealth. Nice!

Hey Chris,

Keyboard Maestro automatically saves changes made to macros and groups.

Sometimes there's a hiccup such that the first execution of a macro after a change fails to reflect the change.

That of course can be very confusing.

-Chris

Good to know about. Thanks

Keyboard Maestro saves the macros automatically, more or less immediately.

But there is a slight delay so what for example a sequence of typing will all be saved as one at the end, not for each character. There is actually a tiny little marker that shows up in the editor window, bottom right, when the macros are currently “dirty”.

After they are saved there will also be a tiny delay while the macros are reloaded by the Keyboard Maestro Engine.

So if you make a change to your macro (including to script text within the macro), and then immediately trigger the macro it is perfectly possible to trigger the macro as it was just before the change.

I will probably add a “Try Whole Macro” button at some point which would avoid this (the Try mechanism works by sending the macro actions to the engine directly, so they are always up to date).

Otherwise, just wait a second or two after the last change before triggering the macro.

Thanks, I understand better now.