On Apr 17, 2015, at 04:00, Jean-Christophe Helary <email@hidden> wrote:I'm having trouble with the notions of "window" and "tab" in Terminal.
… What is the mystery behind tabs and windows in Terminal scripting ?
______________________________________________________________________
Appended are a few examples.
-- Best Regards, Chris
------------------------------------------------------------------------------------------- # Auth: Christopher Stone # dCre: 2015/02/10 14:36 # dMod: 2015/04/17 04:33 # Appl: Terminal # Task: Open a new window in Terminal. # Libs: None # Osax: None # Tags: @Applescript, @Script, @Terminal, @Open, @New, @Window -------------------------------------------------------------------------------------------
tell application "Terminal" if not (exists window 1) then reopen else do script "" end if end tell
-------------------------------------------------------------------------------------------
------------------------------------------------------------------------------------------- # Auth: Christopher Stone # dCre: 2015/03/10 11:37 # dMod: 2015/04/17 04:35 # Appl: Terminal # Task: Run a Script in the active tab of the front window. # Libs: None # Osax: None # Tags: @Applescript, @Terminal, @Run, @Script, @Active, @Tab -------------------------------------------------------------------------------------------
set _dir to POSIX path of (path to downloads folder)
tell application "Terminal" activate tell front window if busy = false then set shCMD to "'ls' -lp " & _dir do script shCMD in selected tab end if end tell end tell
-------------------------------------------------------------------------------------------
------------------------------------------------------------------------------------------ # Auth: Christopher Stone # dCre: 2011/10/16 02:11 # dMod: 2012/08/28 00:55 # Appl: Finder, Terminal # Task: CD to Front Finder Window's Directory. # Libs: None # Osax: None # Tags: @Applescript, @Terminal, @CD, @Front, @Finder, @Window ------------------------------------------------------------------------------------------
try
tell application "Finder" if (count of windows) > 0 then set winTarget to target of front window as alias else set winTarget to path to desktop end if end tell
set winTarget to quoted form of (POSIX path of winTarget)
tell application "Terminal" if (busy of front window) = true then do script "cd " & winTarget else if (busy of front window) = false then tell front window do script "cd " & winTarget in selected tab end tell end if end tell
on error eMsg number eNum tell me to display dialog eMsg & return & return & eNum end try
------------------------------------------------------------------------------------------
|