1

我正在尝试在 Applescript 中编写一个脚本,以全屏​​和自制风格打开终端,然后让终端执行我编写的 java 程序。然后该程序将在终端(无 GUI)中运行。

到目前为止,这是我的代码。我已经能够让终端全屏并输入命令,但我无法自制

tell application "Terminal"
    do script "cd 'desktop/java/Amerika'; javac 'Amerika.java'; java 'Amerika'"
end tell

tell application "Terminal"
tell application "System Events"
        keystroke "f" using {control down, command down}
   end tell
end tell

这是另一个脚本,如果我将它添加到前一个脚本中,只需在自制软件中打开一个新的终端窗口,有时全屏,有时不

tell application "System Events"
   tell process "Terminal"
      tell menu item "Homebrew" of menu "New Window" of menu item "New Window" of   menu "Shell" of menu bar item "Shell" of menu bar 1
          click
       end tell
   end tell
end tell

第一个代码也有一些问题,因为它有时会打开一个全屏终端,有时它不会。

有没有办法让终端以全屏和自制风格打开然后执行一些东西?

4

2 回答 2

1

您还可以更改当前设置属性:

tell application "Terminal"
    do script "uptime"
    set current settings of result to settings set "Homebrew"
    activate
end tell
tell application "System Events"
    keystroke "f" using {control down, command down}
end tell
于 2013-03-28T17:02:51.320 回答
0

这应该可以:(有点样板但你肯定可以提取你需要的东西)

请注意,在执行脚本之前,您不能进入全屏模式,因为这不起作用。

if my UIscript_check(true) then

    if my do_submenu("Terminal", "Shell", "New Window", "Homebrew") then

        tell application "Terminal"

            -- here your script --
            do script "echo " & quoted form of "this is my script" in window 1

        end tell

        tell application "System Events"
            keystroke "f" using {control down, command down}
        end tell

    else
        beep
    end if

end if


on do_menu(app_name, menu_name, menu_item)
    try
        -- bring the target application to the front
        tell application app_name
            activate
        end tell
        tell application "System Events"
            tell process app_name
                tell menu bar 1
                    tell menu bar item menu_name
                        tell menu menu_name
                            click menu item menu_item
                        end tell
                    end tell
                end tell
            end tell
        end tell
        return true
    on error error_message
        return false
    end try
end do_menu

on do_submenu(app_name, menu_name, menu_item, submenu_item)
    try
        -- bring the target application to the front
        tell application app_name
            activate
        end tell
        tell application "System Events"
            tell process app_name
                tell menu bar 1
                    tell menu bar item menu_name
                        tell menu menu_name
                            tell menu item menu_item
                                tell menu menu_item
                                    click menu item submenu_item
                                end tell
                            end tell
                        end tell
                    end tell
                end tell
            end tell
        end tell
        return true
    on error error_message
        return false
    end try
end do_submenu

on UIscript_check(with_msg)
    -- get the system version
    set the hexData to system attribute "sysv"
    set hexString to {}
    repeat 4 times
        set hexString to ((hexData mod 16) as string) & hexString
        set hexData to hexData div 16
    end repeat
    set the OS_version to the hexString as string
    if the OS_version is less than "1030" then
        display dialog "This script requires the installation of Mac OS X 10.3 or higher." buttons {"Cancel"} default button 1 with icon 2
    end if
    -- check to see if assistive devices is enabled
    tell application "System Events"
        set UI_enabled to UI elements enabled
    end tell
    if UI_enabled is false then
        if (with_msg) then
            tell application "System Preferences"
                activate
                set current pane to pane "com.apple.preference.universalaccess"
                display dialog "This script utilizes the built-in Graphic User Interface Scripting architecture of Mac OS X which is currently disabled." & return & return & "You can activate GUI Scripting by selecting the checkbox \"Enable access for assistive devices\" in the Universal Access preference pane." with icon 1 buttons {"OK"} default button 1
            end tell
        end if
        return false
    else
        return true
    end if
end UIscript_check
于 2013-03-28T02:06:21.590 回答