Inhaltsverzeichnis

AppleScript

Mein erstes AppleScript

Beispiel: Backup-Starten (macup.sh) und Runterfahren:

Starte Terminal und ssh

tell application "Terminal"
	do script with command "ssh user@server.de"
	set name_of_window to (get name of front window)
	set id_of_window to (get id of front window)
	set active_tab_of_window to (get selected tab of window id id_of_window) as record
	set active_tab_of_window_record to active_tab_of_window as list
	set active_tab_of_window_record_id to (get item 3 of active_tab_of_window_record) as integer
	set custom title of tab active_tab_of_window_record_id of window id id_of_window to "user@server.de"
        activate
end tell

2. Version: ermittel den eigenen Dateinamen, um damit den Zielrechner zu bestimmen (dann reich ein einfaches Kopieren der Datei für einen neuen Server).

tell application "iTerm"
	
	# eigenen Dateinamen ermitteln (ohne Pfad und ohne .app) -> myName
	set myPath to path to me as text
	if myPath ends with ":" then
		set n to -2
	else
		set n to -1
	end if
	set AppleScript's text item delimiters to ":"
	set myName to text item n of myPath
	if (myName contains ".") then
		set AppleScript's text item delimiters to "."
		set myName to text 1 thru text item -2 of myName
	end if
	set AppleScript's text item delimiters to ""
	
	set Hostname to myName
	
	set Terminalfenster_1 to (make new terminal)
	tell Terminalfenster_1
		#set number of columns to 80
		#set number of rows to 25
		
		set Tab_1 to (make new session at the end of sessions)
		tell Tab_1
			activate
			set name to Hostname
			#set background color to "black"
			#set foreground color to "green"
			#set transparency to "0.1"
			exec command "/bin/bash"
			write text "ssh " & Hostname
		end tell -- Tab_1	
	end tell -- Terminalfenster_1	
end tell

Starte Chicken of the Vnc Sitzung

do shell script ("\"/Applications/Chicken of the VNC.app/Contents/MacOS/Chicken of the VNC\" --Display 25124 chicago.sscvp.net &> /dev/null &")

Besonderheiten:

Mail.app: Account (de-)aktivieren

tell application "Mail"
	set ist_aktiv to (get enabled of account "NUREG")
	set enabled of account "NUREG" to not ist_aktiv
end tell

iTerm mit mehreren Tabs und mit Kommandos

set box_user to "kfr"
set my_boxes to {„host1.de“, „host2.de“}
set ssh_opt to "-L 4040:localhost:4040 -p 23765 "
set my_cmd to {"sudo bash", "apt-get update", "apt-get upgrade -V", "checkrestart"}

tell application "iTerm"
	activate
	set t to (make new terminal)
	tell t
		(* Loop over the boxes, create a new tab and connect. *)
		repeat with box in my_boxes
			activate current session
			launch session "Default Session"
			tell the last session
				set conn to "ssh " & ssh_opt & box_user & "@" & box
				set name to box_user & "@" & box
				write text conn
				repeat with cmd in my_cmd
					write text cmd
				end repeat
			end tell
		end repeat
	end tell
end tell