diff --git a/README.md b/README.md index 200a82a..deb3190 100644 --- a/README.md +++ b/README.md @@ -36,7 +36,7 @@ Apart from that, there is no limitation on the script language. You can use Bash, Python, Swift, Ruby, whatever. And of course, you can always write a script wrapper to call something else. -=> If you can call the script with `open` (e.g., `open myscript`), it will work in the status menu too. +=> If you can run the script with `open` (e.g., `open myscript`), it will work in the status menu too. ### Configuration @@ -46,6 +46,7 @@ There are a few ways to modify the menu structure: #### Menu Icon A subdirectory can have a custom icon if the folder contains an image file named `icon.X` (where `X` is one of: `svg`, `png`, `jpg`, `jpeg`, `gif`, `ico`, `icns`). +For menu items, the icon file should be named exactly like the script file plus one of the icon extensions (e.g., `cmd.sh` -> `cmd.sh.png`). #### Sort Order diff --git a/src/main.swift b/src/main.swift index 28d4b56..8ba1216 100755 --- a/src/main.swift +++ b/src/main.swift @@ -317,18 +317,20 @@ struct Entry { func icon() -> NSImage? { var img: NSImage? = nil - if isDir { + if !hasDynParent { + let basePath = self.isDir ? self.url.appendingPathComponent("icon") : self.url for ext in ["svg", "png", "jpg", "jpeg", "gif", "ico", "icns"] { - let iconPath = self.url.appendingPathComponent("icon." + ext) + let iconPath = basePath.appendingPathExtension(ext) if FileManager.default.fileExists(atPath: iconPath.path) { img = NSImage(contentsOf: iconPath) break } } - if img == nil { + if img == nil, self.isDir { img = NSImage(named: NSImage.folderName) } - } else if action == .Dynamic || hasDynParent { + } + if img == nil, action == .Dynamic || hasDynParent { let cmd = Exec(file: self.url, env: ["ACTION": "icon", "ITEM": hasDynParent ? self.title : ""]) img = NSImage(data: cmd.readData()) }