• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag
 

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Scripting Terminal ?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Scripting Terminal ?


  • Subject: Re: Scripting Terminal ?
  • From: Jean-Christophe Helary <email@hidden>
  • Date: Sat, 18 Apr 2015 21:25:38 +0900

Tommy, Christopher,

Thank you very much for your explanations. That's really now what I wanted to hear :) but I guess that's also a way to investigate other ways to use Applescript to do the thing one has in mind...

Jean-Christophe

> On Apr 18, 2015, at 19:39, email@hidden wrote:
>
> Hello.
>
> Here is a handler I use for scripting tabs in the terminal, with an example call.
> It is as Christopher said, problematic, sometimes, something times out, probably because that Terminal doesn’t digest an event, which I believe may happen if something is busy in a terminal window (hence the timout of 5 minutes).
>
> my termScriptInNewTab("cd " & the_path)
>
>
> on termScriptInNewTab(theStartOfCmd)
> 		global multiple_items, first_item
> 		-- http://nik.me/blog/applescript-tricks-what-do-when-frontmost-window-isnt-frontmost
> 		-- This version is tinkered a little bit, in order to work from an applet, and tinkered to reuse tabs.
>
> 		set cmd to theStartOfCmd & " && echo -n  $'\\ec'"
> 		with timeout of 200 seconds
> 			tell application "Terminal"
> 				activate
> 				set termWins to count of windows
> 				set frontWin to 0
> 				repeat with i from 1 to (count of windows)
> 					try
> 						set tabCount to count of tabs of window i
> 						set frontWin to i
> 						exit repeat
> 					end try
> 				end repeat
> 				if frontWin is 0 then
> 					do script with command cmd
> 					set my first_item to false
> 				else
> 					if (multiple_items and first_item is true) or multiple_items is false then
> 						set first_item to false
> 						set frontmost of window frontWin to true
>
> 						set tabToUse to -1
> 						repeat with j from 1 to tabCount
> 							if (count of every word of (get history of tab j of window 1 as text)) is my nrOfWordsInPrompt then
> 								set tabToUse to j
> 								exit repeat
> 							end if
> 						end repeat
> 						if tabToUse is not -1 then
> 							set selected of tab tabToUse of its window 1 to true
> 							do script with command cmd in (tab tabToUse of window 1)
> 						else
> 							tell application id "sevs" to tell (first application process whose name is "Terminal") to keystroke "t" using {command down}
> 							set xi to 0
> 							repeat until (count of tabs of window 1) is (tabCount + 1)
> 								if xi ≤ 4 then -- don't wait more than one second
> 									delay 0.25
> 								else
> 									set xi to -1
> 									exit repeat
> 								end if
> 							end repeat
> 							if xi is not -1 then
> 								do script with command cmd in (last tab of window 1)
> 							else
> 								do script with command cmd
> 							end if
> 						end if
> 					else
> 						-- multiple items is true and first item is false
> 						tell application id "sevs" to tell (first application process whose name is "Terminal") to keystroke "t" using {command down}
> 						set xi to 0
> 						repeat until (count of tabs of window 1) is (tabCount + 1)
> 							if xi ≤ 4 then -- don't wait more than one second
> 								delay 0.25
> 							else
> 								set xi to -1
> 								exit repeat
> 							end if
> 						end repeat
> 						do script with command cmd in (last tab of window 1)
>
> 					end if
> 				end if
> 			end tell
> 		end timeout
> 	end termScriptInNewTab
>
>
>
> _______________________________________________
> Do not post admin requests to the list. They will be ignored.
> AppleScript-Users mailing list      (email@hidden)
> Help/Unsubscribe/Update your Subscription:
> Archives: http://lists.apple.com/archives/applescript-users
>
> This email sent to email@hidden


 _______________________________________________
Do not post admin requests to the list. They will be ignored.
AppleScript-Users mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
Archives: http://lists.apple.com/archives/applescript-users

This email sent to email@hidden


  • Follow-Ups:
    • Re: Scripting Terminal ?
      • From: Christopher Stone <email@hidden>
References: 
 >Scripting Terminal ? (From: Jean-Christophe Helary <email@hidden>)
 >Re: Scripting Terminal ? (From: Christopher Stone <email@hidden>)
 >Re: Scripting Terminal ? (From: Jean-Christophe Helary <email@hidden>)
 >Re: Scripting Terminal ? (From: Christopher Stone <email@hidden>)
 >Re: Scripting Terminal ? (From: email@hidden)

  • Prev by Date: Re: Scripting Terminal ?
  • Next by Date: Re: Why does opening any script editor open many other apps?
  • Previous by thread: Re: Scripting Terminal ?
  • Next by thread: Re: Scripting Terminal ?
  • Index(es):
    • Date
    • Thread