V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
eairjhioaegnh
V2EX  ›  macOS

或许可以使用 Hammerspoon 写个菜单栏插件来替代掉 ventura 丑陋的输入法图标

  •  
  •   eairjhioaegnh · 337 天前 · 1248 次点击
    这是一个创建于 337 天前的主题,其中的信息可能已经有所发展或是发生改变。
    待我去把 lua 入个门!
    第 1 条附言  ·  337 天前

    来了来了

    第 2 条附言  ·  337 天前
    -- ~/.hammerspoon
    -- ├── Spoons
    -- │   └── CurrentInputSource.spoon
    -- │       └── init.lua
    -- └── init.lua ✅
    
    local CurrentInputSource = hs.loadSpoon('CurrentInputSource')
    CurrentInputSource:start()
    
    第 3 条附言  ·  337 天前
    -- ~/.hammerspoon
    -- ├── Spoons
    -- │   └── CurrentInputSource.spoon
    -- │       └── init.lua ✅
    -- └── init.lua
    
    local obj = {}
    local abcImage = hs.image.imageFromPath("/System/Library/Input Methods/JapaneseIM-RomajiTyping.app/Contents/PlugIns/JapaneseIM-RomajiTyping.appex/Contents/Resources/Roman.tiff"):template(true)
    local pinyinImage = hs.image.imageFromPath("/System/Library/Input Methods/SCIM.app/Contents/PlugIns/SCIM_Extension.appex/Contents/Resources/pinyin.tiff"):template(true)
    
    function isCurrentInputSource(sourceName, isMethod)
        if isMethod then
            return sourceName == hs.keycodes.currentMethod()
        else
            return sourceName == hs.keycodes.currentLayout()
        end
    end
    
    function currentInputSourceIcon()
        if isCurrentInputSource("ABC", false) then
            return abcImage
        elseif isCurrentInputSource("Pinyin - Simplified", true) then
            return pinyinImage
        end
            return nil
    end
    
    第 4 条附言  ·  337 天前
    -- ~/.hammerspoon
    -- ├── Spoons
    -- │   └── CurrentInputSource.spoon
    -- │       └── init.lua ✅
    -- └── init.lua
    
    function obj:init()
        self.menubar = hs.menubar.new(true, "CurrentInputSource")
        self.abc = {
            title = "ABC",
            image = abcImage,
            fn = function()
                if not isCurrentInputSource("ABC", false) then
                    hs.keycodes.setLayout("ABC")
                end
            end,
            checked = isCurrentInputSource("ABC", false)
        }
        self.pinyin = {
            title = "简体拼音",
            image = pinyinImage,
            fn = function()
                if not isCurrentInputSource("Pinyin - Simplified", true) then
                     hs.keycodes.setMethod("Pinyin - Simplified")
                end
            end,
            checked = isCurrentInputSource("Pinyin - Simplified", true)
        }
    
        self.menuItems = {}
        self.menuItems[1] = self.abc
        self.menuItems[2] = self.pinyin
        self.menubar:setMenu(function()
            return self.menuItems
        end)
        self.menubar:setIcon(currentInputSourceIcon())
    end
    
    function obj:start()
        hs.keycodes.inputSourceChanged(function()
            if isCurrentInputSource("ABC", false) then
                self.menubar:setIcon(abcImage)
                self.abc.checked = true
                self.pinyin.checked = false
            elseif isCurrentInputSource("Pinyin - Simplified", true) then
                self.menubar:setIcon(pinyinImage)
                self.abc.checked = false
                self.pinyin.checked = true
            end
        end)
    end
    
    function obj:stop()
        hs.keycodes.inputSourceChanged(nil)
    end
    
    return obj
    
    10 条回复    2023-05-24 03:01:23 +08:00
    K2
        1
    K2  
       337 天前
    不想看到也可以隐藏掉
    eairjhioaegnh
        2
    eairjhioaegnh  
    OP
       337 天前
    @K2 但是还是想看到当前状态
    Socrazy
        3
    Socrazy  
       337 天前
    习惯一下就可以了,现在看高的输入法图标反而不适应了
    Hooluu
        4
    Hooluu  
       334 天前
    留个名,请问如何更改啊?非程序员,看的云里雾里,T T
    eairjhioaegnh
        5
    eairjhioaegnh  
    OP
       334 天前
    @Hooluu 没法更改,是关掉系统本身的,自己用系统图标文件新建一个菜单栏图标
    Hooluu
        6
    Hooluu  
       334 天前
    @eairjhioaegnh 完全听不懂,T T
    eairjhioaegnh
        7
    eairjhioaegnh  
    OP
       334 天前
    @Hooluu 1. 下载安装 Hammerspoon ,https://github.com/Hammerspoon/hammerspoon/releases/latest
    2. 下载 Spoon 插件,https://wwcg.lanzouy.com/i07ur0wyl46d ,解压后将 CurrentInputSource.spoon 移动到 /Users/用户名 /.hammerspoon/Spoons/,将 init.lua 移动到 /Users/用户名 /.hammerspoon/
    3. 打开 Hammerspoon ,点击菜单栏图标(锤子模样),点击”Reload Config"
    Hooluu
        8
    Hooluu  
       334 天前
    @eairjhioaegnh 按照你的步骤操作,木有效果,不折腾了,我直接干脆把搜狗输入法图标自己 PS 修改变宽,反向让图标和系统默认丑陋的输入法图标一样的宽度,顺眼多了,doge
    eairjhioaegnh
        9
    eairjhioaegnh  
    OP
       334 天前
    @Hooluu 咱们强迫症太难了😂
    Hooluu
        10
    Hooluu  
       332 天前
    @eairjhioaegnh 只能说苹果现在越来越不尊重自己立下的设计规范了。ε=(´ο`*)))唉
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   2796 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 28ms · UTC 14:38 · PVG 22:38 · LAX 07:38 · JFK 10:38
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.