My first AppleScript

Pythoneer

Tuesday, August 2. 2005

My first AppleScript

I read the book two months ago, but I never wrote a line of AppleScript. But now I did!

-- Open the terminal application and two windows
-- the right window shall be a python shell and shall
-- have the full height and be at the right edge of the screen
-- the first window stays at the left side of the screen
-- in normal size
tell application "Terminal"
  activate

-- this is cruel, there is no "make new window" I have
-- to step through the menu
-- yucky ... but it works .... jippi
-- thanks to to Fork on #ignmac and to
-- http://bbs.applescript.net/viewtopic.php?pid=32691
tell application "System Events"
   click menu item "Neues Shell-Fenster" of menu "Ablage"\
   of menu bar item "Ablage" of menu bar 1 of process "Terminal"
end tell

tell window 1
set position to {0, 0}
end tell

-- get the width+height of the screen
-- http://www.macosxhints.com/article.php?story=20050428173653581
try
  set window_info to do shell script\
  "defaults read com.apple.loginwindow\
  | grep -w 'NSWindow Frame About This Mac'"
  set screen_width to (word 13 of window_info as number)
  set screen_height to (word 14 of window_info as number)
on error -- use defaults on failure
  set screen_width to 1024
  set screen_height to 768
end try

-- set window 2 dims
tell window 2
  set position to {screen_width - 1000, 0}
  set size to {1000, screen_height}
end tell

-- open the python shell in window 2
do script "clear; python" in window 2

end tell

Posted by Wolfram in Programming at 11:27
Comments (4)
Trackbacks (0)

Trackbacks
Trackback specific URI for this entry

No Trackbacks

Comments
Display comments as (Linear | Threaded)

this is cruel, there is no "make new window" I have to step through the menu How about: tell application "Terminal" activate do script with command "" end tell
#1 Ian on 2005-08-02 13:02 (Reply)
cool. yeah that's not so ugly. Thanks
#1.1 Wolfram Kriesing (Homepage) on 2005-08-02 13:07 (Reply)
ALso, if you want a tidier solution to the screen size, you could get Jon's Commands. That way instead of set window_info to do shell script\ "defaults read com.apple.loginwindow\ | grep -w 'NSWindow Frame About This Mac'" set screen_width to (word 13 of window_info as number) set screen_height to (word 14 of window_info as number) you could just use set s to screen size of item 1 of (screen list) However, if you want to use this on multiple computers, you'd need to be sure Jon's Commands were installed on each.
#1.1.1 Ian on 2005-08-02 16:41 (Reply)
It's true. Graham's right. I feel insulted by seeing apple-script.
#2 Florian (Homepage) on 2005-08-02 16:41 (Reply)

Add Comment


To prevent automated Bots from commentspamming, please enter the string you see in the image below in the appropriate input box. Your comment will only be submitted if the strings match. Please ensure that your browser supports and accepts cookies, or your comment cannot be verified correctly.
CAPTCHA

 
 

Calendar

Back August '08
Mon Tue Wed Thu Fri Sat Sun
        1 2 3
4 5 6 7 8 9 10
11 12 13 14 15 16 17
18 19 20 21 22 23 24
25 26 27 28 29 30 31

Quicksearch

Categories

  • XML JavaScript
  • XML Mac stuff
  • XML Miscellaneous
  • XML Missing or not found
  • XML Music
  • XML Private
  • XML Programming


All categories

Archives

August 2008
July 2008
June 2008
Recent...
Older...

supersized.org

Owner login

supersized s9y blog hosting
Free s9y blog!

Disclaimer

Syndicate This Blog

XML RSS 0.91 feed
XML RSS 1.0 feed
XML RSS 2.0 feed
ATOM/XML ATOM 0.3 feed
ATOM/XML ATOM 1.0 feed
XML RSS 2.0 Comments

Top Referrers

www.google.com (8)
aenzioat.741.com (3)
bekaqkja.kogaryu.com (3)
machinegun.00freehost.com (3)
rettzemk.servetown.com (3)
www.google.ca (3)
www.google.co.uk (2)
www.google.com.pk (1)
www.google.de (1)
www.google.nl (1)

Top Exits

The owner of supersized.org is not responsible for any content on this page!