-
Posts
342 -
Joined
-
Last visited
-
Days Won
11
Content Type
Blogs
Gallery
Downloads
Events
Profiles
Forums
Articles
Media Demo
Everything posted by Jasondm007
-
Filtering JSON Output: A Very Basic Python Question
Jasondm007 replied to Jasondm007's topic in Discussion & Help
@deanisheI have a quick question that relates to an iteration of script above, but is, more generally, related to the way that script filters operate. I was wondering it is possible to capture or pass-on the user's initial query/input (i.e., as the argument itself)? For example, if you wanted to add a modifier/mods to the JSON output whose argument/arg is just the user's query, would this be possible? I tried several versions of the following JSON lines, but the script filter always just passes the {query} on as a string (i.e., not the actual query that a user types into the script filter) "mods": { "cmd": { "subtitle": "TEXT", "arg": "{query}", "icon": {"path": "fileName.png"}, }, }, If you're wondering why in the world someone would want to do this: In circumstances where I can't find what I'm looking for with the script filter above, I was hoping to use a modifier that would just send the query to a different script filter. That way, my lazy @$$ doesn't have to type it in again. Thanks again for all of your help with everything!- 36 replies
-
- script filter
- python
-
(and 1 more)
Tagged with:
-
Any chances this coming soon, @Andrew? šļø Thanks for your consideration!
- 9 replies
-
- web search
- web bookmarks
-
(and 1 more)
Tagged with:
-
@nikivi I was looking for a solution to a different problem when I came across your post. In short, I struggled with the same clipboard/image issue in the past, and wound up making a simplistic workflow that dumps the most recent clipboard entry on the desktop as a jpg. It's hardly perfect, but it might help you get by until Alfred adds a more interactive clipboard. In any event, I've uploaded it for you here: https://gofile.io/d/AeWYKH Although it only works with the most recent clipboard entry, you could always add an argument to the front that allows you to specify which clipboard entry for it to use. Hope this helps!
-
@svinter Sorry for the slow response. Unfortunately, I don't think there's been any traction with this specific issue or the more broad one, concerning access to built-in workflows. I've begged for this in the context of file actions, a few times, but no luck ... just quite yet. š @Andrew
- 9 replies
-
- web search
- web bookmarks
-
(and 1 more)
Tagged with:
-
Filtering JSON Output: A Very Basic Python Question
Jasondm007 replied to Jasondm007's topic in Discussion & Help
@deanishe Thanks for taking a look at it again. As usual, your suggestion worked perfectly! I'm looking forward to going back and updating some of my other scripts. Thanks a ton!! @vitor Thanks for the editor suggestion, too. I just installed Visual Studio Code, and it's output is definitely a lot easier to see than working directly in Alfred or using Atom or BBEdit. Thanks!! By chance, do either of you guys have any suggestions for resources or tutorials for python newbies who would like to do a little tinkering in Alfred, etc.?- 36 replies
-
- script filter
- python
-
(and 1 more)
Tagged with:
-
Filtering JSON Output: A Very Basic Python Question
Jasondm007 replied to Jasondm007's topic in Discussion & Help
@deanishe Thanks again for all of your help. And, for the editor suggestions, too! I haven't tried either of those editors yet, so I'll check them out. Much appreciated! As for script itself, I'm afraid that I keep getting the same string indices error. I've included the script below, and uploaded a test workflow at the link provided. My apologies for not uploading the workflow earlier. I didn't think there'd be enough people with DEVONthink to have any interest (or people to test, for that matter). In any case, thanks again for any help you can lend! Download Test Workflow > #!/usr/bin/python # -*- coding: UTF-8 -*- import plistlib import os import json titles_remove = {"Title A", "Title B", "Title C"} filePath = os.path.expanduser("~/Library/Application Support/DEVONthink 3/SmartGroups.plist") if os.path.exists(filePath): result = {"items": []} plObjList = plistlib.readPlist(filePath) for plobj in plObjList: result["items"].append({ "title": plobj["name"], "subtitle": "Open Smart Group", "uid": plobj["name"], "arg": plobj["sync"]["UUID"]}) #print(json.dumps(result)) #unfiltered_output = json.dumps(result) #filtered_output = [d for d in unfiltered_output if d["title"] not in titles_remove] result = [d for d in result if d['title'] not in titles_remove] print(json.dumps(filtered_output)) else: print('{"items": [{"title": "Error","subtitle": "No Smart Groups Found"}]}')- 36 replies
-
- script filter
- python
-
(and 1 more)
Tagged with:
-
Filtering JSON Output: A Very Basic Python Question
Jasondm007 replied to Jasondm007's topic in Discussion & Help
@deanishe Thanks a ton for getting back to me. This is super helpful! Although I've run into this issue on several occasions, this post was prompted by my frustration trying to modify a portion of Charles Ma's workflow (which I had originally changed to read a different plist file in DEVONthink). I tried implementing your suggestions in a couple of different ways, but am running into similar errors as before. I've included one such iteration below. The line that is commented out is essentially where the script used to stop. I assume I'm implementing the "for" loop incorrectly? #!/usr/bin/python # -*- coding: UTF-8 -*- import plistlib import os import json titles_remove = {"Title A", "Title B", "Title C"} filePath = os.path.expanduser("~/Library/Application Support/DEVONthink 3/SmartGroups.plist") if os.path.exists(filePath): result = {"items": []} plObjList = plistlib.readPlist(filePath) for plobj in plObjList: result["items"].append({ "title": plobj["name"], "subtitle": "Open Smart Group", "uid": plobj["name"], "arg": plobj["sync"]["UUID"]}) #print(json.dumps(result)) unfiltered_output = json.dumps(result) filtered_output = [d for d in unfiltered_output if d["title"] not in titles_remove] print(json.dumps(filtered_output)) else: print('{"items": [{"title": "Error","subtitle": "No Smart Groups Found"}]}') Thanks again for all of your help! Relatedly, do you have a favorite editor for testing python scripts? I've always liked the simplicity of Apple's Script Editor and was hoping to find something equally as easy to work with. At the moment, I've usually just tinkered around in Alfred with python scripts or Atom & BBEdit but I find their outputs difficult to see. Thanks again!- 36 replies
-
- script filter
- python
-
(and 1 more)
Tagged with:
-
I have a very basic python question that I was hoping to get a little help with that involves filtering out list items in a script filter. At the moment, the script filter works great except that it includes a few items I'd prefer not to see in Alfred's output. Is there any easy way to remove items whose titles can be found in another list? Admittedly, I normally do these sorts of things in AppleScript - which is pretty easy to do in this case - except that Iāve been trying to learn a little python, given all of the limitations with AppleScript (which @deanishe and @vitor have rightly reminded me of on numerous occasions, so hopefully this will make them proud š). For example, letās say that I have the following list: titles_remove = {"Title A", "Title B", "Title C"} And, before outputting my results in Alfred, Iād like to remove all items whose titles can be found in titles_remove. At the moment, my script filter ends with the following line: print(json.dumps(result)) And, itās JSON output follows the usual format where each item has a title, subtitle, uid, and arg. Now, if I modify that last line so that itās output is: unfiltered_output = json.dumps(result) What should I do next to remove items whose titles can be found in the titles_remove list? I tried following several different python tutorials, but I kept receiving errors. I suspect that some of the methods weren't intended for dealing with strings. But I'm a complete newbie here. Thanks for any help you can lend! I really appreciate it. And, if anyone has any advice for python newbies that might want to do things with Alfred, I'd greatly appreciate any recommendations on potential resources to check out, etc. Thanks!!
- 36 replies
-
- script filter
- python
-
(and 1 more)
Tagged with:
-
Is there a way to sequentially feed different file names through Alfredās replace utilities and then apply them to the appropriate files at the end? By way of background, I have a workflow that Iāve been using religiously for a few years which takes a file name and then feeds it through numerous replace utilities to help me name the research-related articles on my computer in a consistent manner (mostly pdfs). As you might imagine, each individual replace utility is specific to a particular source or naming convention from my field (fixing commas, odd characters, capitalization issues based on where I download them from, etc.). The workflow is a real lifesaver, as itās helped me take control of my research in ways that I just hadnāt done a good job with prior to using Alfred. My central problem with the workflow is that it only works with one file name at a time. In short, the workflow either grabs the name of selected file from Finder, DEVONthink or a File Action, then it pushes the name through a series of replace utilities, and finally it applies the cleaned up name to the selected file once its done (depending on its source - Finder/DEVONthink/File Action). Since I imagine that others are transforming text in a similar fashion with Alfredās replace utilities, I was wondering if anyone might know how to best approach redesigning my workflow to operate with more than one file name at a time? Is there a way to match the original and new (post-cleanup) file names so that I can apply them to the correct files? Does anyone know of another workflow that uses a similar technique or that might help me better understand how to approach this issue? Thanks in advance for any help you can lend! I really appreciate it.
-
Need to press Shift twice for QuickLook [Fixed 4.1.1 b1171 pre-release]
Jasondm007 replied to vitor's topic in Closed
Works great on my end now, too! Thanks @Andrew (and @vitor)!! -
Need to press Shift twice for QuickLook [Fixed 4.1.1 b1171 pre-release]
Jasondm007 replied to vitor's topic in Closed
@vitor FWIW - I've had this issue for quite some time, too. macOS 10.15.6 Alfred 4.1.1 (1170) -
I would love to be able to directly access all of Alfred's default file actions in my workflows. @Andrew recently added some awesome new actions for the buffer - and, Alfred already included some of the other default file actions, like Reveal and Browse - but I'd love to be able to access other default file actions, too - such as Open With, Recent Documents, etc. At the moment, if you want to access these without extra steps, you have to use GUI-based approaches that type the file action's name into the File Action panel, which are always imminently fragile and problematic. There are a variety of ways this could be implemented, but here are some early thoughts: Create a new action, in the Actions section - perhaps called Run File Action - where the user can use a drop down to select the file action they would like to run on the file paths that are being passed to it. You might think of it as a more specific application of the "Action in Alfred" action. At a minimum, the dropdown should be populated by whatever file actions the user has enabled (Features > Actions > File Actions). However, if you wanted to get fancy, it'd be even better if the dropdown included both Alfred's file actions AND any the user has created. In theory, the dropdown might operate something like Alfred's "Call External" output, except that it is displaying Alfred's default file actions and any the user created. Add a new option in the "Action in Alfred" action, which includes a dropdown allowing the user to specify the action that will be run on the file paths included above. The dropdown could operate like either of the options described above (just default file actions or include the user's file actions, too). Unless the user enables this option, of course, the default would be to send the file paths to Alfred's File Actions panel, allowing the user to select for themselves (i.e., the same way they do now). Add a new option to the "Call External Trigger" output that allows the user to access Alfred's default file actions Provide AppleScript access - enhance this existing "actions" command. Example: tell application "Alfred" to action OpenWith theFilePaths If I had to choose from these options, I'd probably go with the first or second option. But I honestly don't care how it gets accomplished! And, while I didn't include it above, if you really wanted to step things up, I would include some kind of error feedback mechanism - such as a notification, etc - for when users pass file paths to file actions they should not have - such as when they've passed more than one file to an action that can only handle one file, or when the file action is tied to a specific file type that does not match the files the user is trying to pass to it. Again, these are just fancy bells and whistles, I'm not picky here!! @Andrew Is there any way we can get better access to Alfred's default file actions? š They're great, and I'd like to start tapping in to these more - as opposed to trying to recreate them myself, in a workflow, or going to GUI route. As always, thanks for your consideration! Long Live Alfred!!
- 3 replies
-
- file action
- feature request
-
(and 1 more)
Tagged with:
-
Apple Music Workflow to add Current Song to Playlist
Jasondm007 replied to csaborio's topic in Workflow Help & Questions
@csaborio & @dfay Out of curiosity, do you guys know if this issue has improved since your last post (re: Add Apple Music track to playlists and/or user library, etc.)? I'd like to be able to: Add the current track playing from Apple Music to my user library (so that it's now in my library, or so that I can later add it to playlist, etc.), and Add the current track playing from Apple Music directly to a playlist without first adding it to my user library As for the first issue, I've had a little luck using the following line to get the track into my library: duplicate current track to source "Library" However, it's incredibly slow and buggy. So, if you're lucky, and it actually works, then you still have to put a ton of delays in the script to give it time to add it to your library (so that you can later search for it and add it a playlist, etc.). For example, the following AppleScript uses this method and tries to add the track to a predefined playlist called Inbox š„: tell application "Music" set thePlaylist to user playlist "Inbox š„" set trackName to name of current track set artistName to artist of current track try duplicate current track to source "Library" delay 8 set foundTracks to (every track of library playlist 1 whose artist is artistName and name is trackName) repeat with theTrack in foundTracks duplicate theTrack to thePlaylist end repeat set theNotification to ("Added ā " & artistName & ", " & trackName) on error set theNotification to ("Failed ā " & artistName & ", " & trackName) end try return theNotification end tell However, the script doesn't work very well (even after tinkering around with the delays). And, as for the second item, I haven't made any progress with it (i.e., short of using a hokey way of accessing the right-click/context menu to add it to a playlist). But this almost never works. Any ideas? Thanks for your help!!- 7 replies
-
- add to playlist
- itunes
-
(and 2 more)
Tagged with:
-
JSON Output & Variables with Emojis - Encoding Woes
Jasondm007 replied to Jasondm007's topic in Discussion & Help
@deanishe & @vitor Yeah, I hear you. I keep trying to peck at the other languages, but have struggled. If I told you how much time I've spent on these (and other terrible) workflows, you'd laugh. As you can tell, I don't work in tech and barely understand AppleScript. Baby steps! Ha While I'm obviously not familiar with these things, I still find it somewhat surprising there isn't a better library/dictionary for AppleScript to use for purposes of JSON outputs. The one that I relied on in the example - which is also used by a lot of other Alfred workflows - hasn't been maintained for years. In fact, its creator commented a few years ago that he was surprised people were still using it. In any case, thanks to @deanishe & @vitor's help, I created another test workflow. For those who might be interested, one of the script filters allows you to play any playlists in your library and the other allows you to move a selected playlist to any playlist folders you might have created. The later is super helpful if, like me, you hate dragging things around or right-clicking a ton of times. The former runs a little slow on my machine, but that's probably more due the mess of playlists I have in my library than anything. Click here to download: https://share.getcloudapp.com/NQugBAdO PS: @deanishe I'm sorry for sending the (JavaScript) script filters to AppleScript. š¤¦āāļø- 10 replies
-
- json
- script filter
-
(and 4 more)
Tagged with:
-
JSON Output & Variables with Emojis - Encoding Woes
Jasondm007 replied to Jasondm007's topic in Discussion & Help
@deanishe Thanks a ton for taking a crack at it. I really appreciate it. As you would expect, you script works perfectly! And, @deanishe & @vitor your comments were also really helpful, too. I'm going to try and wrap my head around them, and get back to you. At the end of the day, it's obvious that I just need to start getting better with other languages š¤¦āāļø. Thanks again!- 10 replies
-
- json
- script filter
-
(and 4 more)
Tagged with:
-
JSON Output & Variables with Emojis - Encoding Woes
Jasondm007 replied to Jasondm007's topic in Discussion & Help
@deanishe Thanks for getting back to me. While I might not have done it correctly, before posting this, I tried adding "Unicode" to the text references in the script above. However, it didn't fix the problem. I might be totally wrong about it encoding an issue? Oddly enough, the emojis and everything seem to show up just fine in Script Editor. Thanks!- 10 replies
-
- json
- script filter
-
(and 4 more)
Tagged with:
-
Iām struggling to get a script filter to work which outputs a variable containing a mixture of text and emojis. In the output, Alfred just spits out empty characters for the emojis (ā° question mark in a box). Thereās obviously an encoding issue Iām overlooking, and I havenāt been able to quite put my thumb on it. To explain, Iāve created a script filter with AppleScript thatās supposed to let the user select a playlist from their Apple Music library (to play it, move it, etc). I recently moved over from Spotify to Apple Music, and I have a ton of playlists (put that's a separate problem - ha)! And, as you might guess, some of my playlists include emojis. When I run the script filter, Alfredās output just shows empty characters where the emojiās used to be. Consider the following example: Playlist: Radiohead ā Faves Script Filter/Alfred Output: Radiohead ā° Faves Debug: Radiohead \u2b50 Faves So, while most of this is over my head, from what I understand, my JSON output is being spit out as formatted for C/C++/Java Src (when it should be in the usual utf8 unicode format). Any suggestions for fixing it? I've never tinkered around with JSON.scpt file that does all of the heavy lifting, so hopefully it's just a minor issue with my code. Admittedly, Iāve always been confused about how JSON and AppleScript work together. Although Iāve been able to create script filters in the past thanks to everyoneās help, Iāve never made one that dealt with text that containing emojis. Thanks for any help you can lend! For testing purposes, Iāve uploaded a test workflow here: https://share.getcloudapp.com/xQuDN0dl. And, here's screenshot of its script filter:
- 10 replies
-
- json
- script filter
-
(and 4 more)
Tagged with:
-
@brunoc I figured out how to implement the local smart group search, in a relatively hackneyed manner by making a few minor changes to the workflow's "dtp-list-groups.applescript" file. For some reason, you have to use the string version of "smart group." I have no idea why, but apparently it's a known problem? In any case, here's the updated portion for others that might also want to be able to select local smart groups: on reiterateOnGroup(theRec, thisDB) set my numCurrentLevel to (my numCurrentLevel) + 1 tell application id "DNtp" repeat with r in (every child of theRec) set rType to ((type of r) as string) if ((type of r is group) or (rType is "smart group")) and (name of r is not in my lstIgnoredGroups) then my addToGroups(name of r, uuid of r, thisDB) if ((my numCurrentLevel < my numLevelMax) and (rType is not "smart group")) then my reiterateOnGroup(r, thisDB & " āø " & name of r) end if else if (my boolSearchTags is true) and (type of r is group) and (name of r is "Tags") and (my numCurrentLevel is 1) then set tmpSaveLevelMax to my numLevelMax set my numLevelMax to 2 my reiterateOnGroup(r, thisDB & " āø " & name of r) set my numLevelMax to tmpSaveLevelMax end if end repeat end tell set my numCurrentLevel to (my numCurrentLevel) - 1 end reiterateOnGroup
-
@brunoc Previously, I asked about the possibility of adding Global Smart Groups to your workflow, which I'm sure is quite the Herculean task given how different they are from the standard groups the workflow currently searches for. Would it be possible - and perhaps much easier - to, instead, add an option for the workflow to search for local smart groups (similar to how you've added an option for searching tags)? Personally, I've started using these a lot lately. And, since they don't have the same sidebar section as global smart groups, your workflow would be great for quickly accessing them. Thanks for your consideration! I use this workflow religiously these days!!
-
This is a relatively minor feature request, but I'd love it if Alfred's Bookmarks search displayed each bookmark's full folder hierarchy. At the moment, it only shows the enclosing/parent folder's name in brackets. While my folder hierarchy for bookmarks is relatively simple compared to other files, there are some areas where I'd find it incredibly helpful to get more information about the location of each bookmark (particularly with research-related bookmarks). To explain what I'm looking for, consider the following example for a bookmark to this forum, which is located in a folder called Alfred. Within my bookmarks, the Alfred folder is located in another folder called Tech. As a result, I'd love for the subtext above to read: [Tech/Alfred] https://www.alfredforum.com/forum And, if the concern is that there will be too much text to read if the full folder hierarchy is included in the subtext, then it might be nice to include one or more of the following options (in PreferencesāFeaturesāWeb Bookmarks): Parent Folder + URL (current): Allow users to stick with the default (one folder with URL) (Example: [Alfred] https://www.alfredforum.com/forum) Folder Hierarchy - URL: Include the full folder hierarchy without the URL (Example: Alfred/Tech) Folder Hierarchy + URL: Show everything, even though most of the URL might get cut off (Example: [Alfred/Tech] https://www.alfredforum.com/forum) As always, thanks for your consideration!
-
- feature request
- bookmarks
-
(and 2 more)
Tagged with:
-
RecentlyAdded ā List directory contents by added date
Jasondm007 replied to vitor's topic in Share your Workflows
No problem - many thanks for taking at a stab at it though!