found drama

get oblique

applescript.

by Rob Friesel

For Pete … following our conversation the other day about AppleScript, here’s a brief concoction for your noodle:

(* first, let's launch some apps for fun: *)

(* we'll start w/ just Mail *)

tell application "Mail"

  activate

end tell

(* then we'll launch Safari and size the window *)

tell application "Safari"

  activate

  repeat with i from 1 to the count of documents

    do JavaScript "moveTo(0,0);self.resizeTo(screen.availWidth,screen.availHeight)" in document i

  end repeat

end tell

(* then we'll launch iChat, size its window, and position it so *)

tell application "iChat"

  activate

  copy the bounds of window 1 to {x1, y1, x2, y2}

  set the window_width to x2 - x1

  set the window_height to y2 - y1

  set the bounds of window 1 to {0, 22, window_width, 22 + window_height}

end tell

(* now we'll attempt to mount a shared Windows volume *)

try

  mount volume "smb://WORKGROUP;username@computerName/ShareName"

end try

(* but that's not enough, we need to back up some data too *)

do shell script "rsync -CSraztue ssh --exclude="\.*" --no-whole-file ~/Documents /Volumes/ShareName/backup_dir"

(* and since we don't need that mounted volume anymore... *)

eject SHARENAME

(* and since we're expecting visitors via VNC: *)

tell application "OSXvnc"

  activate

end tell

(* and the "System Events" hack to activate OSXvnc *)

tell application "System Events"

  tell process "OSXvnc"

    tell window "OSXvnc (1.32)"

      click button "Start Server"

    end tell

  end tell

end tell

Hopefully that’s a good starter set.

About Rob Friesel

Software engineer by day. Science fiction writer by night. Weekend homebrewer, beer educator at Black Flannel, and Certified Cicerone. Author of The PhantomJS Cookbook and a short story in Please Do Not Remove. View all posts by Rob Friesel →

Leave a Reply

Your email address will not be published. Required fields are marked *

*

*