簡體   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