ctucx.git: nixfiles

ctucx' nixfiles

1 
2 
3 
4 
5 
6 
7 
8 
9 
10 
11 
12 
13 
14 
15 
16 
17 
18 
19 
20 
21 
22 
23 
24 
25 
26 
27 
28 
29 
30 
31 
32 
33 
34 
35 
36 
37 
38 
39 
40 
41 
42 
43 
44 
45 
46 
47 
48 
49 
50 
51 
52 
{ pkgs, lib, ... }:

let
  setIcon = pkgs.writeScript "setIcon.osascript" ''
    #!/usr/bin/env osascript

    use framework "AppKit"

    --------------------------------------------------------------------------------
    # PROPERTY DECLARATIONS:
    property this : a reference to current application
    property NSWorkspace : a reference to NSWorkspace of this
    property NSImage : a reference to NSImage of this

    --------------------------------------------------------------------------------
    # IMPLEMENTATION:
    on run argv
      set icon to item 1 of argv
      set target to item 2 of argv

      setIcon to icon for target
    end run
    --------------------------------------------------------------------------------
    # HANDLERS:
    to setIcon to iconPath for filePath
      set sharedWorkspace to NSWorkspace's sharedWorkspace()
      set newImage to NSImage's alloc()
      set icon to newImage's initWithContentsOfFile:iconPath

      set success to sharedWorkspace's setIcon:icon forFile:filePath options:0
    end setIcon
  '';

  apps = {
    "Telegram.app"       = ./icons/Telegram.icns;
    "coconutBattery.app" = ./icons/coconutBattery.icns;
    "LibreOffice.app"    = ./icons/LibreOffice.icns;
    "Firefox.app"        = ./icons/Firefox.icns;
    "Thunderbird.app"    = ./icons/Thunderbird.icns;
  };

in {

  system.activationScripts.postActivation.text = (lib.concatStringsSep "\n\n" (lib.mapAttrsToList (app: icon: ''
    # Change app-icon for: ${app}
    if [ ! -e $'/Applications/${app}/Icon\r' ]; then
      echo -n "Update ${app} Icon: "
      ${setIcon} ${icon} /Applications/${app};
    fi
  '') apps));

}