How to pass a path to the terminal?

Well, actually my Execute a Script in Terminal action is also just an AppleScript, no magic involved :wink:. This is the script from the action:

AppleScript content of Execute a Script in Terminal action
# Description: Part of a KM action. Passes a command or script to the Terminal.
# Author: Tom Floeren
# Version: 2.1.0
# Mod. Date: 2017-12-06


set winFront to system attribute "KMPARAM_Bring_Terminal_to_foreground"
set winNew to system attribute "KMPARAM_New_Terminal_window"
set theScript to do shell script "echo $KMPARAM_Script"
set kmVars to system attribute "KMPARAM_KM_variables"

# Get KM variables if any
if length of kmVars > 0 and kmVars does not start with "Optional." then
	set inst to system attribute "KMINSTANCE"
	set varDefs to ""
	set c to 0
	tell application id "com.stairways.keyboardmaestro.engine"
		repeat with p in paragraphs of kmVars
			if length of p > 0 then # Ignore empty lines
				set v to getvariable p instance inst
				set c to (c + 1)
				set varDefs to varDefs & "km" & c & "=" & quoted form of v & ";" & space
			end if
		end repeat
	end tell
	set theScript to varDefs & theScript
end if

# Run script in Terminal
if winNew is "1" then
	tell application id "com.apple.Terminal"
		launch
		do script theScript
		if winFront is "1" then activate
	end tell
else
	tell application "Terminal"
		launch
		if winFront is "1" then activate
		set windowCount to (count of the windows)
		if windowCount is greater than 0 then
			repeat with w from 1 to windowCount
				if window 1 is busy or history of window 1 contains "[Process completed]" then
					set frontmost of window 1 to false
				else
					do script theScript in window 1
					set frontmost of window 1 to true
					return
				end if
			end repeat
		end if
		tell window 1
			do script theScript
			set frontmost to true
		end tell
	end tell
end if


By the way, @Filou, the last version of the action is 2.1.0. Saying this because above you posted a link to version 2.0.0.

(Due to the forum settings it is (or was) not possible to edit a new version into the OP of a topic, as posts get locked after a while. So before you download a macro or action, it is always a good idea to slowly scroll down the topic, until the very bottom, to see if there are any updates posted later.)

2 Likes