Applescripting my Terminal startups

Discussion in 'macOS' started by ltHank, Nov 4, 2008.

  1. ltHank macrumors newbie

    Joined:
    Nov 4, 2008
    #1
    Most of the time I just putz around in Terminal for kicks and giggles, other times I use to augment some other process I am doing or running simple terminal programs/tools.

    Then come the times that I want to write code in Terminal. This is a really low impact script, but what I want is to have Terminal automatically configure itself to have the windows set up the way that I want by automatically launching a window preset. Here is the code that I have thus far:

    APPLESCRIPT:
    tell application "Finder"
    activate
    open application file "Terminal.app" of folder "Utilities" of folder "Applications" of startup disk
    end tell

    tell application "Terminal"
    if (count of windows) is 1 then
    tell application "System Events" to tell process "Terminal" to keystroke "w" using command down
    end if
    delay 1.5
    if (count of windows) is 1 then
    tell application "System Events" to tell process "Terminal" to keystroke "return"
    end if

    if (count of windows) is 0 then
    tell application "System Events" to tell process "Terminal" to click "coding: two files, tall" of menu item "Open Window Group" of menu "Window" of menu bar 1
    end if
    end tell
    : APPLESCRIPT

    The first part of the code is just to clear the default window that opens on Terminal start up. Usually I just use that, but for these cases I don't want it.

    The part where the hang up happens is here:
    if (count of windows) is 0 then
    tell application "System Events" to tell process "Terminal" to click "coding: two files, tall" of menu item "Open Window Group" of menu "Window" of menu bar 1
    end if

    The script editor returns "Access not allowed," but I think it is just that I don't know how to say what I'm trying to say. No error is returned if I only use 'tell application "System Events" to tell process "Terminal" to click menu item "Open Window Group" of menu "Window" of menu bar 1,' but that also doesn't accomplish anything. So, how do I access an option from the menu item "Open Window Group"?

    Alternately, is there another way to reach that without using the route that I currently am?
     
  2. ltHank thread starter macrumors newbie

    Joined:
    Nov 4, 2008
    #2
    Ach, managed to figure out my problem by working around with the help of a couple of other websites. Here was the fix:

    if (count of windows) is 0 then
    tell application "System Events" to tell process "Terminal" to click the menu item "coding: two files, tall" of menu "Open Window Group" of menu item "Open Window Group" of menu "Window" of menu bar 1
    end if

    There is a little of what I would consider redundancy, but I can only assume this is Applescript forcing me to be very specific. What is important is that it works!
     

Share This Page