Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/317.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 如何在全屏和自制模式下打开终端,并使用Applescript编写脚本_Java_Terminal_Applescript_Homebrew - Fatal编程技术网

Java 如何在全屏和自制模式下打开终端,并使用Applescript编写脚本

Java 如何在全屏和自制模式下打开终端,并使用Applescript编写脚本,java,terminal,applescript,homebrew,Java,Terminal,Applescript,Homebrew,我正试图用Applescript编写一个脚本,以全屏和自制的方式打开终端,然后让终端执行我编写的java程序。然后,该程序将在终端中工作(无GUI) 这是到目前为止我的代码。我已经能够让终端全屏显示并输入命令,但我不能让它自制 tell application "Terminal" do script "cd 'desktop/java/Amerika'; javac 'Amerika.java'; java 'Amerika'" end tell tell application "

我正试图用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
第一个代码也有一些问题,因为它有时打开全屏终端,有时不打开

有没有办法让终端以全屏和自制的方式打开,然后执行一些操作?

应该可以:(有点像锅炉板,但你肯定可以提取你需要的东西)

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

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
这应该行得通:(锅炉板有点多,但你肯定可以提取你需要的东西)

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

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

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

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

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

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
稍微慢一点(或者可能只是我的电脑),但也可以工作。谢谢稍微慢一点(或者可能只是我的电脑),但也可以工作。谢谢