繁体   English   中英

AppleScript:带有主题专业版的新终端窗口

[英]Applescript: new terminal window with theme pro

我想创建一个脚本,以主题主题pro打开一个新的终端窗口。 该脚本看起来如何? 我只是设法获得一个新窗口,但我想指定主题。

我为此创建了一个自动服务,因为我想使用快捷方式。

我需要适当的主题主题或从中获取信息,以某种方式进行重建。


这样就可以正常工作:

将模式设置为{"Basic", "Grass", "Novel", "Ocean", "Pro", "Red Sands"}将I设置为1到6之间的随机数

将主题设置为模式的项目I

但是如何获得当前主题? 脚本执行完毕后会丢失其所有变量吗?还是以某种方式保存了它?

应该这样做:

tell application "Terminal" to set current settings of (do script) to settings set "Pro"

不确定,您的意思是什么,但是:

我将需要适当的主题主题或从中获取信息,以某种方式进行重建。

我编写了此applescript,以便可以轻松设置当前窗口的主题。 它允许我设置一个特定的主题,在一个祝福的主题中随机选择一个主题,或在所有可用主题中随机选择一个主题。

我在.bashrc中使用别名设置来从命令行轻松调用此设置。 示例在标题中。

-- StyleTerm.scpt
-- Sets theme of current terminal window/tab

-----------------------
-- Arguments
-----------------------
-- If a theme name is provided on the command line then set to that
-- Example
--   osascript StyleTerm.scpt Grass
--  
-- If multiple theme names are provided on command line then choose randomly among those
--    This allows for random behavior from within blessed set
-- Example
--   osascript StyleTerm.scpt Grass Basic Ocean "Red Sands"
--  
-- If no command line args are provided then choose randomly among all themes
-- Example
--   osascript StyleTerm.scpt
-----------------------

-----------------------
-- This is best utilized via aliases set up in shell config file
-- Examples from my .bashrc
--   # Theme specific aliases
--   alias grass='osascript ~/sbin/StyleTerm.scpt Grass'
--   alias basic='osascript ~/sbin/StyleTerm.scpt Basic'
--   # Random from blessed themes
--   alias btheme='osascript ~/sbin/StyleTerm.scpt Grass Basic Ocean "Red Sands"'
--   # Random themes
--   alias rtheme='osascript ~/sbin/StyleTerm.scpt'
-----------------------

on run argv
    tell application "Terminal"
        if (count argv) is 0 then
            -- Use random theme from all possible themes
            set newTheme to some settings set
            set current settings of selected tab of front window to newTheme
        else
            -- Use random theme from arguments 
            set newThemeName to some item argv
            set current settings of selected tab of front window to first settings set whose name is newThemeName
        end if
    end tell
end run

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM