AppleScript behavior depending of the execution context

I experience change in result depending of the manner an AppleScript is invoked in Keyboard Maestro.
Consider this simple test code:

tell application "Path Finder"
   set sel_files to (get selection)
   repeat with fs in sel_files
	set fs1 to item 1 of fs
	set m to (class of fs1 as string)
   end repeat
end tell
m

When one or more files are selected the value of ‘m’ is:

  • “fsFile” <= Keyboard Maestro [Execute text script] (hopefully the same as execution inside AppleScript Editor)
    but
  • “«class cfiL»” <= Keyboard Maestro [Execute script file]

More annoying changes occurs with characters including diacritic marks…

Is there a way to make the behavior of “Keyboard Maestro [Execute script file]” identical to the (more satisfying) one of “Keyboard Maestro [Execute text script]”?

Alain

Keyboard Maestro asks the osascript tool to execute the script, whether it is a text script or a compiled script.

The only reason that would make a difference would be the different environments that the script is compiled in. But I’m afraid that is all black magic as far as I am concerned. Why the system does it one way in one place and another way in another place is well beyond me. Maybe @ccstone has some clue. I don’t.

Thanks Peter,
Alain

Nope.

If you run a compiled script from the Terminal with osascript you get «class cfiL», so as Peter says the trouble is not with Keyboard Maestro.

In any case Path Finder’s fsFile class is useless and needs to be converted to an alias or Posix Path for portability.

I rate this problem as a bug, but it’s Apple’s bug.


Best Regards,
Chris

If I summarize:

# Path Finder>file:
# "«class cfiL»" in Terminal "osascript test.scpt", Keyboard Maestro [Execute script file]
# "fsFile"       in Script Editor 2.7, Keyboard Maestro [Execute text script]
# Path Finder>folder:
# "«class cfoL»" in Terminal "osascript test.scpt", Keyboard Maestro [Execute script file]
# "fsFolder"     in Script Editor 2.7, Keyboard Maestro [Execute text script]

Nevertheless I use, perhaps naively, this result for filtering of selection item’s as file / folder depending of the current task.

It is too bad, Peter fixes (rare) bugs much more easily than Apple :wink:

Thanks Christopher for your always interesting and helpful comments.

All the best,
Alain

Hey Alain,

# Convert Path Finder's fsFile references into more portable aliases.
tell application "Path Finder"
  set selList to selection
  repeat with i in selList
    set (contents of i) to (((POSIX path of i) as POSIX file) as alias)
  end repeat
end tell

# Get class of items.
tell application "Finder"
  repeat with i in selList
    set itemClass to class of (item (i as text))
  end repeat
end tell


Best Regards,
Chris

Thanks Chris to help me to learn AppleScript on the field with accute example :wink:

Here is the Finder summarizing table of class results counterpart of the different Path Finder one of this post

# Finder>file:
# "«class docf»"  in Terminal "osascript test.scpt", Keyboard Maestro [Execute script file]
# "document file" in Script Editor 2.7, Keyboard Maestro [Execute text script]
# Finder>folder:
# "«class cfol»"  in Terminal "osascript test.scpt", Keyboard Maestro [Execute script file]
# "folder"        in Script Editor 2.7, Keyboard Maestro [Execute text script]

Best,
Alain