Korny Posted September 23, 2020 Posted September 23, 2020 Hi - I'm a relative Alfred newbie, so apologies if this is obvious or answered somewhere that I missed! I'm trying to run a bash script which outputs a number of file names, and then allow the user to act on those files, like they would on the results of a normal search - opening the file, revealing it in finder, etc. (The script is running a custom `ripgrep` command - similar to `grep -l` - which just spits out matching filenames) But I can't work out how to get the results of the script to be treated as multiple files - if I pass it to (say) the "File Buffer" action, which sounds like it might be what I want, it does nothing - and from looking at the debugger output, it seems like my bash script output is treated as one large string, instead of a number of separate lines. Is this possible? Would it help if the output was JSON not lines? (I could pipe it through `jq` if I needed JSON) At the moment I have switched to running it in a terminal, which is good enough for now - but it feels like it'd be nice to be able to integrate this sort of thing into Alfred more completely.
vitor Posted September 23, 2020 Posted September 23, 2020 5 hours ago, Korny said: if I pass it to (say) the "File Buffer" action, which sounds like it might be what I want, it does nothing It must be doing something, namely adding it to the File Buffer. Otherwise it must be outputting something to the debugger. Separate the full paths to the files by tabs, so Alfred understands it’s several and connect it to an Action in Alfred Action, which seems to be what you want.
deanishe Posted September 23, 2020 Posted September 23, 2020 2 hours ago, vitor said: Separate the full paths to the files by tabs You should be able to use a JSON array since Alfred 4.1. It's not yet documented, as it was added kinda last minute and support might not be complete. The File Buffer action definitely supports it, as that's why support for multiple arguments was added IIRC.
Korny Posted September 25, 2020 Author Posted September 25, 2020 Thanks folks - I'll try JSON as it's probably less fiddly than tabs! (I did mention the debugger in my original post :) It did indeed do _something_ - just nothing visible outside the debugger)
TomBenz Posted July 14, 2022 Posted July 14, 2022 Dear all I want to open multiple files selected in Finder in their online onedrive version. For one file, the workflow below works well (original source: . This is the code that I am using. How do I use the output of this in next "open url" block to do custom search using each file name? from os.path import basename import re, sys query = "{query}" # replace strings seperated with <tab> for new lines query = re.sub('\t', '\n', query) # convert multiline string into list query = query.splitlines() # get the number of list contents num = len(query) # get basename of each list element and replace it for i in range(0,num): query = basename(query) # convert list into multiline string again wynik = "\n".join(query) # print without trailing new line sys.stdout.write(wynik)
vitor Posted July 18, 2022 Posted July 18, 2022 @pankajsz When asking for help, please share the Workflow, not just pasted code and screenshots. That forces people to decipher and recreate your Workflow mentally. To get help, strive to make less work for the helper. For example, you’re using {query} but should be using argv (though in this case it is probably OK), but it’s difficult to suggest what to change if I don’t know how your Workflow is set up.
TomBenz Posted July 20, 2022 Posted July 20, 2022 On 7/19/2022 at 5:15 AM, vitor said: @pankajsz When asking for help, please share the Workflow, not just pasted code and screenshots. That forces people to decipher and recreate your Workflow mentally. To get help, strive to make less work for the helper. For example, you’re using {query} but should be using argv (though in this case it is probably OK), but it’s difficult to suggest what to change if I don’t know how your Workflow is set up. Yes @vitor. will do it. I uploaded Alfred workflow that works well on single file at https://we.tl/t-bPIYNlsNSY and need assistance to make it work for multiple files I have also attached AppleScript that works on multiple files -- I can't figure out how to merge these things together.
vitor Posted July 26, 2022 Posted July 26, 2022 (edited) This should work. You’ll need the latest Alfred pre-release. Take a look at the code in the Run Script, and see how much smaller it can be and remain readable. You’ll notice I changed it to with input as argv, meaning sys.argv[1] instead of {query}. That will save you having to escape things and is in general better (hence why it’s the default). Edited July 26, 2022 by vitor
TomBenz Posted July 26, 2022 Posted July 26, 2022 5 hours ago, vitor said: This should work. You’ll need the latest Alfred pre-release. Take a look at the code in the Run Script, and see how much smaller it can be and remain readable. You’ll notice I changed it to with input as argv, meaning sys.argv[1] instead of {query}. That will save you having to escape things and is in general better (hence why it’s the default). thanks vitor. the link above doesn't work for me. Request you to please upload via alternative way
luckman212 Posted July 26, 2022 Posted July 26, 2022 This is cool, but in case someone wants a step that doesn't require installing python3 (which isn't preinstalled on any macOS...) this zsh script should also accomplish the same thing, unless I am missing something?
vitor Posted July 26, 2022 Posted July 26, 2022 3 minutes ago, luckman212 said: unless I am missing something? You’re not, that’ll work too. But @pankajsz already had partial code which looks like they wrote it themselves, so I opted to fix it in their chosen language instead of rewriting as a shell script. Python is far from being my language of choice, but when you’re learning it’s better to correct the course than veer wildly. With the former you can try to understand what changed and add it to your arsenal; with the latter you’re left with the proverbial fish but not the fishing skills. Not to say that I disagreed with sharing the Zsh code; I don’t in the slightest. Merely explaining my choice in this situation since you asked. In a case where the Python code had to be fifteen lines and the Zsh code three, I’d have eschewed the Python route. Technically you don’t even need the Run Script and Split Args, you can replace both with the Get Path Basename Automation Task that went live with yesterday’s 2022.8 release. That I did mean to mention but forgot. luckman212 1
TomBenz Posted July 27, 2022 Posted July 27, 2022 10 hours ago, vitor said: Looks like the link got cut off. Try now. This works great. If I select and run on two files, it opens safari tabs three times. The last one is without any filename passed.
TomBenz Posted July 27, 2022 Posted July 27, 2022 9 hours ago, luckman212 said: This is cool, but in case someone wants a step that doesn't require installing python3 (which isn't preinstalled on any macOS...) this zsh script should also accomplish the same thing, unless I am missing something? Tried this but it doesn't open the custom_url step after run script.
TomBenz Posted July 27, 2022 Posted July 27, 2022 9 hours ago, vitor said: You’re not, that’ll work too. But @pankajsz already had partial code which looks like they wrote it themselves, so I opted to fix it in their chosen language instead of rewriting as a shell script. Python is far from being my language of choice, but when you’re learning it’s better to correct the course than veer wildly. With the former you can try to understand what changed and add it to your arsenal; with the latter you’re left with the proverbial fish but not the fishing skills. Not to say that I disagreed with sharing the Zsh code; I don’t in the slightest. Merely explaining my choice in this situation since you asked. In a case where the Python code had to be fifteen lines and the Zsh code three, I’d have eschewed the Python route. Technically you don’t even need the Run Script and Split Args, you can replace both with the Get Path Basename Automation Task that went live with yesterday’s 2022.8 release. That I did mean to mention but forgot. If possible, please share the workflow using these new features from the latest release. will use it for learning and for future use.
vitor Posted July 27, 2022 Posted July 27, 2022 7 hours ago, pankajsz said: If I select and run on two files, it opens safari tabs three times. As I said: 23 hours ago, vitor said: You’ll need the latest Alfred pre-release. In which that won’t happen. 7 hours ago, pankajsz said: using these new features from the latest release. It’s described above: 16 hours ago, vitor said: you don’t even need the Run Script and Split Args, you can replace both with the Get Path Basename Automation Task That’s just it. Delete two objects; put a new one in their place. The learning process involves reading instructions and trying to replicate them.
TomBenz Posted July 27, 2022 Posted July 27, 2022 6 hours ago, vitor said: As I said: In which that won’t happen. It’s described above: That’s just it. Delete two objects; put a new one in their place. The learning process involves reading instructions and trying to replicate them. Very simple and easy with Automation task. I used Get Path Basename without extension. thanks
vitor Posted July 27, 2022 Posted July 27, 2022 2 hours ago, pankajsz said: I used Get Path Basename without extension. Even better! That was a later addition. TomBenz 1
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now