我正在尝试用Applescript编写一个脚本,以全屏和自制的方式打开Terminal,然后让Terminal执行我编写的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这是另一个脚本,如果我将它添加到前一个脚本中,只需在homebrew中打开一个新的终端窗口,有时是全屏,有时不是
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第一个代码也有一些问题,因为它有时会打开全屏终端,有时不会。
有没有办法让终端以全屏和自制的方式打开,然后执行一些东西?
发布于 2013-03-28 10:06:22
这应该是可行的:(有点模式化,但你肯定可以提取出你需要的东西)
请注意,在执行脚本之前,您不能进入全屏,因为这将不起作用。
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-29 01:02:51
您还可以更改当前设置属性:
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 tellhttps://stackoverflow.com/questions/15670953
复制相似问题