Run from an Execute an AppleScript action (text script).
------------------------------------------------------------
# Auth: Christopher Stone
# dCre: 2011/10/16 02:11
# dMod: 2014/10/15 10:56
# Appl: Terminal
# Task: CD to Front Finder Window's Directory.
# Libs: None
# Osax: None
# Tags: @Applescript
------------------------------------------------------------
# Try is elided out due to FastScripts' better error dialog.
tell application "Finder" to set _dir to insertion location as alias
tell application "Terminal"
tell selected tab of front window
if its busy = false then
do script "cd " & (quoted form of (POSIX path of _dir)) in it
else
do script "cd " & (quoted form of (POSIX path of _dir))
end if
end tell
end tell
------------------------------------------------------------
(In general it’s a good idea to break up different requests into different posts.)
Keyboard Maestro's Write to a File action DOES create a file if there isn't one and completely rewrites it if it does exist.
Note:
There is also an Append Text to a File action, and it too will create a file if one doesn't exist.
I'm still having a few issues with this. Undoubtedly me but still.
So, my finder action is simply to open terminal (iTerm in my case) at the location of the foremost Finder screen.
Now I have iTerm opening and everything is fine however when I try to CD to the folder it appears that the Applescript is giving me a duff folder.
cd /var/folders/_n/4g1xqtdn1wd3l07xrp13trb80000gn/T/Keyboard-Maestro-Script-831DAE1D-69A9-4884-A49E-8CDFF0831CE2:151:156
To be honest, I’m experimenting at this stage.
I’m a developer so I build kind of fake test websites all the time.
Ultimately I’d like to build two of three smaller sites but iTerm keeps stopping me.
I tried this at the desktop location and also an external drive.
Randomly the desktop works but the external drive doesn’t.
It seems that there is something permissions wise that wont allow Keyboard Maestro to run scripts. It looks like, on first inspection, that within my user folder all is well and the scripts do run.
So I guess its actually permissions rather thab Keyboard Maestro itself.
You're not returning anything appropriate from the AppleScript into your log variable.
You can test AppleScript using the Script Editor.app.
If you're going to use iTerm then use it for everything.
In the current iTerm session:
------------------------------------------------------------
# Auth: Christopher Stone
# dCre: 2015/04/18 02:37
# dMod: 2016/02/15 13:26
# Appl: iTerm
# Task: CD to the Directory of the Front Finder Window (Desktop if no windows are open).
# Libs: None
# Osax: None
# Tags: @Applescript, @Script, @iTerm, @Front, @Finder, @Directory
------------------------------------------------------------
tell application "Finder" to set dirOfFrontWindow to insertion location as alias
set dirOfFrontWindow to POSIX path of dirOfFrontWindow
set dirOfFrontWindow to quoted form of dirOfFrontWindow
set shCMD to "cd " & dirOfFrontWindow
tell application "iTerm"
tell the first terminal
tell the current session
set name to "New Session"
write text shCMD
end tell
end tell
end tell
------------------------------------------------------------
In a NEW iTerm Session:
------------------------------------------------------------
# Auth: Christopher Stone
# dCre: 2015/04/18 02:37
# dMod: 2016/02/15 13:39
# Appl: iTerm
# Task: Create a new terminal session.
# : Then CD to the Directory of the Front Finder Window (Desktop if no windows are open).
# Libs: None
# Osax: None
# Tags: @Applescript, @Script, @iTerm, @Front, @Finder, @Directory
------------------------------------------------------------
tell application "Finder" to set dirOfFrontWindow to insertion location as alias
set dirOfFrontWindow to POSIX path of dirOfFrontWindow
set dirOfFrontWindow to quoted form of dirOfFrontWindow
set shCMD to "cd " & dirOfFrontWindow
tell application "iTerm"
tell (make new terminal)
set newSession to (make new session at the end of sessions)
tell newSession
exec command "/bin/bash -l"
write text shCMD
end tell
end tell
end tell
------------------------------------------------------------