Skip to content
accelerando

Tag Archives: Applescript

Put your mac to rest via ssh

17-Jul-08

Sometimes my Macbook decides to wake up from his sleep (a.k.a hibernation). Most of the times i notice this at work when my emails disappear from my imap inbox as Mail.app applies his rules.

As i do not have Apple Remote Desktop or any other VNC server enabled on my Macbook, i do have a problem.

I can vpn into my home and i can ssh into the Macbook, so i came up with the following solution:

Put the following three lines into a plain textfile, i.e. “sleep.txt” and save it somewhere:

tell application "Finder"
  sleep
end tell

Then, open Terminal.app, change to the directory you saved the file in and execute:

osascript sleep.txt

Your ssh connection will then timeout and the Mac sleeps.

Stupid me forgot that ssh can execute remote commands: From your workmachine execute

ssh my_home_computer 'osascript sleep.txt'

and you’re done. Thanks “tante” for reminding me :)

Alternatively, you can achieve similar with Mail.app itself, have a look at the solution here, but i like mine better.

Search and replace

23-Apr-06

In den meisten “neueren” und höheren Programmiersprachen gibt es eine Stringmethode, die “Suchen und ersetzen” implementiert oder wenigstens Bibliotheken, die so etwas können.
Applescript kann das nicht.

Um auf Planet-Punk.de meine iTunes Charts ohne LastFM präsentieren zu können, brauchte ich aber genau sowas:

on searchAndReplace(s, r, t)
	set d to text item delimiters
	set text item delimiters to s
	set t to t's text items
	set text item delimiters to r
	tell t to set t to beginning & ({""} & rest)
	set text item delimiters to d
	return t
end searchAndReplace

Diese kleine Funktion sucht im Text t nach s und ersetzt jedes Vorkommen durch r.

Zack und schon ‘nen Bug im Code Snippet Plugin für WP gefunden…. Zeile 28 der AppleScript Datei für GeSHi ist falsch:

Statt

'QUOTEMARKS' => array('"',"'"),

darf sie nur

'QUOTEMARKS' => array('"'),

lauten. Wenn man nicht alles selber macht…

Close
E-mail It