FelixKratz / SbarLua

A Lua API for SketchyBar
GNU General Public License v3.0
115 stars 10 forks source link

App icons in spaces? #4

Closed shajra closed 7 months ago

shajra commented 7 months ago

First off, thanks for putting all this work into this project. Some of it is just a slick look-and-feel. But there are nice little things like getting app icon summaries in spaces that are very useful when leaning heavily on spaces. That's implemented in the shell example. I noticed it's not in the Lua example.

With the INFO environment variable, I think this is technically possible now. But I need help converting this JSON string to a Lua data structure. I could find something third-party or write my own. But it's probably easier to just popen a call to jq.

What is more likely to happen in the future is that you would give me this information directly as a Lua data structure. Or did I miss something in the code, and is this already possible?

shajra commented 7 months ago

I got it working... everything I needed was there in env. No need to mess with jq. This is wonderful. Thanks!

FelixKratz commented 7 months ago

This is the script I am using for app icons:

local app_icons = require("app_icons")

local space_windows = sbar.add("item", {
  padding_left=10,
  padding_right=8,
  icon = {
    string = "􀆊",
    font = {
      style = "Heavy",
      size = 16.0,
    },
  },
  label = { drawing = false },
  display = "active",
})

space_windows:subscribe("space_windows_change", function(env)
  local icon_line = ""
  local no_app = true
  for app, count in pairs(env.INFO.apps) do
    no_app = false
    local lookup = app_icons[app]
    local icon = ((lookup == nil) and app_icons["default"] or lookup)
    icon_line = icon_line .. " " .. icon
  end
  if (no_app) then
    icon_line = " —"
  end
  sbar.animate("tanh", 10, function()
    spaces[env.INFO.space]:set({ label = icon_line })
  end)
end)

with app_icons.lua converted from the bash mapping function via chatgpt:

return {
  ["WhatsApp"] = ":whats_app:",
  ["Nova"] = ":nova:",
  ["Signal"] = ":signal:",
  ["Affinity Photo"] = ":affinity_photo:",
  ["Sublime Text"] = ":sublime_text:",
  ["Notion"] = ":notion:",
  ["Pine"] = ":pine:",
  ["Alacritty"] = ":terminal:",
  ["Hyper"] = ":terminal:",
  ["iTerm2"] = ":terminal:",
  ["kitty"] = ":terminal:",
  ["Terminal"] = ":terminal:",
  ["终端"] = ":terminal:",
  ["WezTerm"] = ":terminal:",
  ["Podcasts"] = ":podcasts:",
  ["播客"] = ":podcasts:",
  ["Spark Desktop"] = ":spark:",
  ["Dropbox"] = ":dropbox:",
  ["OmniFocus"] = ":omni_focus:",
  ["TIDAL"] = ":tidal:",
  ["Spotlight"] = ":spotlight:",
  ["Affinity Publisher"] = ":affinity_publisher:",
  ["Replit"] = ":replit:",
  ["Kakoune"] = ":kakoune:",
  ["Code"] = ":code:",
  ["Code - Insiders"] = ":code:",
  ["Microsoft Excel"] = ":microsoft_excel:",
  ["League of Legends"] = ":league_of_legends:",
  ["Obsidian"] = ":obsidian:",
  ["Typora"] = ":text:",
  ["Blender"] = ":blender:",
  ["Microsoft Edge"] = ":microsoft_edge:",
  ["Caprine"] = ":caprine:",
  ["Figma"] = ":figma:",
  ["Folx"] = ":folx:",
  ["Arc"] = ":arc:",
  ["TeamSpeak 3"] = ":team_speak:",
  ["Drafts"] = ":drafts:",
  ["Jellyfin Media Player"] = ":jellyfin:",
  ["Element"] = ":element:",
  ["Numbers"] = ":numbers:",
  ["Numbers 表格"] = ":numbers:",
  ["Airmail"] = ":airmail:",
  ["Preview"] = ":pdf:",
  ["预览"] = ":pdf:",
  ["Skim"] = ":pdf:",
  ["zathura"] = ":pdf:",
  ["zoom.us"] = ":zoom:",
  ["IntelliJ IDEA"] = ":idea:",
  ["Music"] = ":music:",
  ["音乐"] = ":music:",
  ["Safari"] = ":safari:",
  ["Safari浏览器"] = ":safari:",
  ["Safari Technology Preview"] = ":safari:",
  ["Finder"] = ":finder:",
  ["访达"] = ":finder:",
  ["TickTick"] = ":tick_tick:",
  ["Mattermost"] = ":mattermost:",
  ["Calendar"] = ":calendar:",
  ["日历"] = ":calendar:",
  ["Fantastical"] = ":calendar:",
  ["Cron"] = ":calendar:",
  ["Amie"] = ":calendar:",
  ["Todoist"] = ":todoist:",
  ["Live"] = ":ableton:",
  ["Logseq"] = ":logseq:",
  ["Parallels Desktop"] = ":parallels:",
  ["App Store"] = ":app_store:",
  ["ClickUp"] = ":click_up:",
  ["Docker"] = ":docker:",
  ["Docker Desktop"] = ":docker:",
  ["Trello"] = ":trello:",
  ["Microsoft To Do"] = ":things:",
  ["Things"] = ":things:",
  ["Notability"] = ":notability:",
  ["Brave Browser"] = ":brave_browser:",
  ["网易云音乐"] = ":netease_music:",
  ["Messages"] = ":messages:",
  ["信息"] = ":messages:",
  ["Nachrichten"] = ":messages:",
  ["DEVONthink 3"] = ":devonthink3:",
  ["Bear"] = ":bear:",
  ["Notes"] = ":notes:",
  ["备忘录"] = ":notes:",
  ["GrandTotal"] = ":dollar:",
  ["Receipts"] = ":dollar:",
  ["Cypress"] = ":cypress:",
  ["Sequel Pro"] = ":sequel_pro:",
  ["Sequel Ace"] = ":sequel_ace:",
  ["PomoDone App"] = ":pomodone:",
  ["mpv"] = ":mpv:",
  ["Orion"] = ":orion:",
  ["Orion RC"] = ":orion:",
  ["System Preferences"] = ":gear:",
  ["系统设置"] = ":gear:",
  ["Reminders"] = ":reminders:",
  ["提醒事项"] = ":reminders:",
  ["MoneyMoney"] = ":bank:",
  ["MAMP"] = ":mamp:",
  ["MAMP PRO"] = ":mamp:",
  ["Final Cut Pro"] = ":final_cut_pro:",
  ["Microsoft PowerPoint"] = ":microsoft_power_point:",
  ["VLC"] = ":vlc:",
  ["Chromium"] = ":google_chrome:",
  ["Google Chrome"] = ":google_chrome:",
  ["Google Chrome Canary"] = ":google_chrome:",
  ["Xcode"] = ":xcode:",
  ["Canary Mail"] = ":mail:",
  ["HEY"] = ":mail:",
  ["Mail"] = ":mail:",
  ["Mailspring"] = ":mail:",
  ["MailMate"] = ":mail:",
  ["邮件"] = ":mail:",
  ["Vivaldi"] = ":vivaldi:",
  ["Color Picker"] = ":color_picker:",
  ["数码测色计"] = ":color_picker:",
  ["Audacity"] = ":audacity:",
  ["WebStorm"] = ":web_storm:",
  ["Emacs"] = ":emacs:",
  ["GitHub Desktop"] = ":git_hub:",
  ["Setapp"] = ":setapp:",
  ["微信"] = ":wechat:",
  ["Alfred"] = ":alfred:",
  ["Tor Browser"] = ":tor_browser:",
  ["Skype"] = ":skype:",
  ["qutebrowser"] = ":qute_browser:",
  ["Firefox Developer Edition"] = ":firefox_developer_edition:",
  ["Firefox Nightly"] = ":firefox_developer_edition:",
  ["Insomnia"] = ":insomnia:",
  ["LibreWolf"] = ":libre_wolf:",
  ["Tweetbot"] = ":twitter:",
  ["Twitter"] = ":twitter:",
  ["FaceTime"] = ":face_time:",
  ["FaceTime 通话"] = ":face_time:",
  ["Zotero"] = ":zotero:",
  ["1Password 7"] = ":one_password:",
  ["Slack"] = ":slack:",
  ["Spotify"] = ":spotify:",
  ["OBS"] = ":obsstudio:",
  ["Min"] = ":min_browser:",
  ["Default"] = ":default:",
  ["Pi-hole Remote"] = ":pihole:",
  ["VMware Fusion"] = ":vmware_fusion:",
  ["CleanMyMac X"] = ":desktop:",
  ["Telegram"] = ":telegram:",
  ["Bitwarden"] = ":bit_warden:",
  ["Iris"] = ":iris:",
  ["Neovide"] = ":vim:",
  ["MacVim"] = ":vim:",
  ["Vim"] = ":vim:",
  ["VimR"] = ":vim:",
  ["Warp"] = ":warp:",
  ["Zulip"] = ":zulip:",
  ["Thunderbird"] = ":thunderbird:",
  ["Tower"] = ":tower:",
  ["Matlab"] = ":matlab:",
  ["Joplin"] = ":joplin:",
  ["Android Studio"] = ":android_studio:",
  ["Keynote"] = ":keynote:",
  ["Keynote 讲演"] = ":keynote:",
  ["Grammarly Editor"] = ":grammarly:",
  ["Firefox"] = ":firefox:",
  ["Zed"] = ":zed:",
  ["Sketch"] = ":sketch:",
  ["Discord"] = ":discord:",
  ["Discord Canary"] = ":discord:",
  ["Discord PTB"] = ":discord:",
  ["Evernote Legacy"] = ":evernote_legacy:",
  ["Zeplin"] = ":zeplin:",
  ["KeePassXC"] = ":kee_pass_x_c:",
  ["Microsoft Teams"] = ":microsoft_teams:",
  ["카카오톡"] = ":kakaotalk:",
  ["Linear"] = ":linear:",
  ["Microsoft Word"] = ":microsoft_word:",
  ["Atom"] = ":atom:",
  ["Keyboard Maestro"] = ":keyboard_maestro:",
  ["Transmit"] = ":transmit:",
  ["Android Messages"] = ":android_messages:",
  ["Pages"] = ":pages:",
  ["Pages 文稿"] = ":pages:",
  ["Affinity Designer"] = ":affinity_designer:",
  ["VSCodium"] = ":vscodium:",
  ["Reeder"] = ":reeder5:",
  ["Calibre"] = ":book:",
  ["default"] = ":default:" -- Default case
}
shajra commented 7 months ago

Thanks. My Lua isn't the strongest. What I remember from Ion3WM days supplemented with ChatGPT. Here's the function I got that does something pretty similar:

local function space_windows_change(env)
  local app_emojis = {}
  for name, _ in pairs(env.INFO.apps) do
    table.insert(app_emojis, emojis[name] or ":default:")
  end
  icon_strip = "—"
  if next(app_emojis) ~= nil
  then
    icon_strip = table.concat(app_emojis, " ")
  end
  sbar.set(spaces[env.INFO.space], {
    label = icon_strip
  })
end

I think I'll put in the animation.

shajra commented 7 months ago

Hi. Just continuing to chat here because it's convenient and relevant to the thread. You posted your code here, but is it in a repo anywhere? That would be easier to follow. I found your dotfiles repo, but it still seems to be on the shell-style configuration (including the experimental branch).

For now, I'm getting all my latest best ideas for Lua configuration from the example in SbarLua. I actually kind of prefer that. Do you have a plan to push some more features to the example repo here?

I don't yet have much to add beyond what's already there and the small amount I've figured out in this thread.

FelixKratz commented 7 months ago

My personal lua setup is not finalized yet, I work on it on and off but once it is ready I will create a branch in my dotfiles.

FelixKratz commented 7 months ago

I have added a first dotfile version to this branch: https://github.com/FelixKratz/dotfiles/tree/lua