Am using Applescript ( OS X 10.10.5 ) to bring up a choose file dialog and get the chosen filename into a KM variable, so that the filename can be pasted into a textfield.
Returns the Error:
osascript[1091] <Error>: The function ‘CGContextErase’ is obsolete and will be removed in an upcoming update. Unfortunately, this application, or a library it uses, is using this obsolete function, and is thereby contributing to an overall degradation of system performance.
If you set a KM Var in a script, then you do NOT need to return the results of the Execute Script to the same KM Var name, like you are doing with chosen_file_name
In fact, in your script, all you need is this:
tell application "Keyboard Maestro Engine"
setvariable "chosen_file_name" to fname
end tell
If the KM variable doesn’t exist, it will auto-create it for you.
Let’s clean that up and make it more reliable shall we?
---------------------------------------------------------------------------------
# Use a home-based-path.
set strPath to "~/Documents"
# Expand the path to a full POSIX Path with System Events.
tell application "System Events" to set strPath to POSIX path of disk item strPath
# Wrap your choose-file in a tell-block that returns you to the front application.
tell application (path to frontmost application as text)
set fileAlias to choose file with prompt "Please choose a file:" of type ¬
{"png", "svg", "jpg", "gif", "jpeg"} default location strPath
end tell
# Self-explanatory.
tell application "System Events" to set fname to name of fileAlias
tell application "Keyboard Maestro Engine" to setvariable "chosen_file_name" to fname
---------------------------------------------------------------------------------