Jump to content

luckman212

Member
  • Posts

    172
  • Joined

  • Last visited

  • Days Won

    6

luckman212 last won the day on August 1 2020

luckman212 had the most liked content!

Recent Profile Visitors

1,807 profile views

luckman212's Achievements

Member

Member (4/5)

29

Reputation

  1. Wish I had the chops for that @deanishe but it's likely above my pay grade. Maybe I'll try. Do you think in general it's a good idea to switch my configuration to a SQLite db instead of the current plaintext json? My reasons for wanting to do this are mainly: reduce chances of error in data entry ability to query ahead of time to constrain results vs doing the filtering after (although there's a tradeoff of course since once the results are cached, Alfreds builtin filtering is probably faster) ability to quickly sort entries by the various fields currently the config.json data looks like this (sample): [ { "title": "Mnemonics snips folder", "desc": "open folder of snips for this workflow", "keywords": [ "mnemonics","snippets","cfg","config" ], "type": "file", "icon": "f-atom.png", "object": "./snips/", "bundleid": "com.apple.finder", "contexts": [ "com.runningwithcrayons.Alfred-Preferences" ] }, { "title": "Search for executables in Terminal", "keywords": [ "command","find","binaries","perm","perms","type","111" ], "type": "copy", "icon": "terminal.png", "object": "find . -type f -perm 111 ! -name \"*.*\"" }, { "title": "Create symlinks", "desc": "ln -s[fiv] /path/to/file [/path/to/symlink] (default=current dir)", "keywords": [ "soft","hard","command","ln","alias","syntax","link" ], "type": "copy", "icon": "terminal.png", "object": "ln -s /path/to/file /path/to/symlink", "url": "x-man-page://ln" }, ...
  2. Thanks @deanishe and @Mr Pennyworth for the advice and knowledge. Figured I'd share what I ended up with so far, in case it's useful. I'd also welcome any advice on whether this code is utter garbage or wildly unsafe etc, as I am not a Swift developer by any stretch. The below produces a small binary which outputs 3 fields (tab-separated): bundle_id, localized app name, and path. There's some error checking in there but it was a bit of trial and error, so not sure it's correct. I use this in my script filter to filter the results by bundle ID of the frontmost app, and use the App Name and Path in the JSON to prefix the items e.g. "Google Chrome: foo bar" and grab the native app icon to distinguish those results. The workflow is called "Mnemonics" and it's kind of my own TLDR system to help me remember how to do little things e.g. How do I set a variable to the contents of a heredoc in bash? or What's the keyboard shortcut for opening the Artboard in Adobe Illustrator?. I will probably publish it soon. Just need to switch the filter from Bash to Python (to remove the dependency on jq) and switch the config file from plaintxt JSON to SQLite... frontmost.swift (compile with `swiftc frontmost.swift`) import AppKit final class StandardErrorOutputStream: TextOutputStream { func write(_ string: String) { FileHandle.standardError.write(Data(string.utf8)) } } enum frontmostError: Error { case bundleid case path } do { let frontApp: NSRunningApplication = NSWorkspace.shared.frontmostApplication! guard let bundleid: String = frontApp.bundleIdentifier else { throw frontmostError.bundleid } guard let path: String = frontApp.bundleURL?.path else { throw frontmostError.path } let name: String = frontApp.localizedName ?? bundleid print(bundleid, name, path, separator:"\t", terminator:"\n") } catch { var outputStream = StandardErrorOutputStream() print("error: \(error)", to: &outputStream) exit(EXIT_FAILURE) } Bash script filter (partial) IFS=$'\t' read -r bundle_id app_name app_path < <(/usr/local/bin/frontmost) [ -n "$bundle_id" ] || exit /usr/local/bin/jq <config.json \ --arg b "$bundle_id" \ --arg n "$app_name" \ --arg p "$app_path" \ '{ items: [ .[] | select(.contexts != null) | .contexts as $c | select($b | IN($c[])) | ...
  3. @Mr Pennyworth that's cool - how would I use that to get the variable into the script filter? I'd call out to that "./frontmost" executable from inside my Python script? edit: I compiled your swift binary and it is indeed very fast. I got it to work using this #!/usr/bin/python import os try: cmd = '/usr/local/bin/frontmost' bundle_id = os.popen(cmd).read() except: exit(1) ...rest of the workflow I'm sure there are much better/safer ways to do this using e.g. subprocess()... is this the right path to take?
  4. I'm looking for an efficient way to get the bundle ID of the frontmost app into a workflow variable to be used in a script filter. (basically want the script filter to display context-specific results based on the frontmost app) I tried searching for a way to do this but came up short. anyone got a tip? I know I can get this info using e.g. Python... but that seems a bit slow/inefficient #!/usr/bin/python from AppKit import NSWorkspace try: bundle_id = NSWorkspace.sharedWorkspace().frontmostApplication().bundleIdentifier() except: print('unknown') exit(1) if bundle_id: print(bundle_id)
  5. Hi @Andrew wanted to ask if you'd consider adding truncate and/or range transforms to Alfred? This could be useful e.g. in the Snippets feature, if you want to grab the first 50 chars of a clipboard that could contain 1000s of chars: {clipboard:truncate(50)} or in a similar vein, a range command like {clipboard:range(10..50)} to grab chars 10->50 https://www.alfredapp.com/help/workflows/advanced/placeholders/#modifiers
  6. I want to use <shift> in a mods: {...} section to toggle the subtitle to show some other data. The problem frequently manifests itself when tapping shift twice in a row too quickly. No, all results don't have x-man-page:// — they are all sorts of different things, URLs, file paths, strings of text, etc.
  7. Thanks @deanishe that's what I thought... Would be a nice feature to have. I guess the poor man's workaround is to pass your data via another variable and just set arg to null, eh? eg ... title: "no quicklook here!", arg: null, variables: { realarg: "x-man-page://ln" }
  8. It does not seem possible to DISABLE quicklookurl for a script filter, either globally or for an individual JSON object/entry. I tried setting quicklookurl to null, as well as "" — but neither worked. Is this possible at all?
  9. Yes @godbout opening Xcode is another reliable way to trigger this for me too. @Andrew it's most noticable on a cold start (after a fresh boot) of a "large" app like Xcode or Microsoft Excel. Another app that I can definitely repeatedly trigger this with is Setapp. I know this is a bit low-tech but I couldn't figure out another way to capture this, so I recorded a couple of seconds with my phone, so you can get an idea of what this looks like... Setapp... https://user-images.githubusercontent.com/1992842/117302537-bce67e80-ae49-11eb-859a-13400dbecc57.mov Excel... (around 9s is where the hang starts - Excel dock icon was still bouncing...) https://user-images.githubusercontent.com/1992842/117302524-ba842480-ae49-11eb-9883-fa85f9ab5adb.mov
  10. @Vero I know what you mean about newlines being treated differently by different OS'es e.g. Mac vs Windows. But if we confine it to just macOS (since we're only talking Alfred here) the definition is pretty clear: it should be 1 + the count of the "0A" hex bytes in a block of text (excluding a final trailing newline if there is one). I'm looking for the same output that would be shown by this bash script: wc -l <<< "${clipboard%$'\n'}" Not sure what page width has to do with it? I'll give you a simple use case (this happened to me yesterday which is what prompted me to post this request). Let's say someone sends you a list of email addresses, and you've copied them to the clipboard. You want to know how many email addresses you have. It would be great if I could just flip open Alfred's clipboard history and see it there without having to paste this into Sublime Text to see the linecount etc.
  11. @giovanni Thanks but that's not the same. Having it display in the clipboard viewer gives you the ability to quickly flip through history items and see the count, vs having to place items in the clipboard first and then run a workflow.
  12. Currently, the clipboard viewer (very helpfully) shows the word and character counts: Just a suggestion: it would be useful to also display the line count here, if possible!
  13. Just wanted to post a little note on this: I discovered an option I wasn't aware of today in Alfred's Appearance > Options area: I thought maybe this would have some effect on this problem, but alas I tested it and they are both affected by the thread lock. I'm now using Alfred v4.3.4.1229
  14. Hi @Andrew - I just tested & the menubar hat goes zombie as well (other menubar icons are ok). So whatever's going on with this thread locking is across the board.
×
×
  • Create New...