Applescript:带有主题 pro 的新终端窗口

发布于 2024-10-28 04:20:45 字数 332 浏览 1 评论 0原文

我想创建一个脚本,打开一个主题为 pro 的新终端窗口。该脚本会是什么样子?我刚刚设法获得一个新窗口,但我想指定主题。

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

我需要主题的属性或从中获取信息,以某种方式重建它。


这样效果很好:

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

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

但是如何获取当前主题?脚本完成后是否会丢失所有变量,或者是否以某种方式保存它?

I want to create a script which opens me a new terminal window with the theme pro. how would that script look like? I just managed to get a new window but I want to specify the theme.

I created a automator service for that, cause I want to use shortcuts.

I would need a propertie for the theme or get the infos out of it, somehow for rebuilding it.


So that works fine:

Set mode to {"Basic", "Grass", "Novel", "Ocean", "Pro", "Red Sands"}
set I to random number from 1 to 6

Set theme to item I of mode

But how can I get the current theme? And does the script loos all its vars after its finished or does it somehow save it?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

℡寂寞咖啡 2024-11-04 04:20:46

这应该可以:

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

不过不确定你的意思是什么:

我需要主题的属性或从中获取信息,以某种方式重建它。

This should do:

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

Not sure, what you mean by this, though:

i would need a propertie for the theme or get the infos out of it, somehow for rebuilding it.

〆凄凉。 2024-11-04 04:20:46

我编写了这个 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

I wrote this applescript so that I could easily set the theme of the current window. It allows me to set to a specific theme, a random one among a blessed set, or randomly among all available.

I uses aliases setup in my .bashrc to easily invoke this from the command line. Examples are in the header.

-- 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
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文