gingerbeardman Posted June 11, 2023 Share Posted June 11, 2023 (edited) This workflow allows you to search for games on Moby Games. I'd like to add image thumbnail more game data for each result alternative titles (foreign titles as defaults are US-centric) more search types https://github.com/gingerbeardman/alfred-mobygames/ It is a bit early to be submitted to the Gallery. I plan to add to it, but I feel there is a simpler way of me translating the Moby Games API JSON to Alfred JSON? This is my first time using `jq`. So I am here to learn. Edited June 11, 2023 by gingerbeardman Link to comment
vitor Posted June 14, 2023 Share Posted June 14, 2023 You should always prefer with input as argv over with input as {query}. You’re escaping too much so some characters won’t be sent correctly. Also, you should likely be URL escaping the input text. Something like: USER_INPUT="${1}" # This assumes with input as argv, ${1} replaces {query} ESCAPED="$(osascript -l JavaScript -e "function run(argv) { return encodeURIComponent(argv[0]) }" "${USER_INPUT}")" RAW=......&title=${ESCAPED}") Long story short: your current approach will work now as you’re typing ASCII but it might break if a user types a special character. Note that the ; is redundant. You only need that if you have two things on the same line. Unlike JavaScript, where it’s a matter of style, in shell pretty much no one ends all lines with a semicolon. On 6/11/2023 at 6:51 PM, gingerbeardman said: image thumbnail To do that, small trick I use on Short Films:Download the images to alfred_workflow_cache (be sure to create the folder: mkdir -p "${alfred_workflow_cache}")Before every download, check if you already have it and use it if you do.Once downloaded, check what’s the smaller of the two dimensions (width or height) then crop it to that to get a perfectly fitting square. This can all be done with sips which ships with macOS. I can get more specific later if you go that route. On 6/11/2023 at 6:51 PM, gingerbeardman said: I feel there is a simpler way of me translating the Moby Games API JSON to Alfred JSON? If the code is working, I don’t really see anything wrong with your approach. There’s a “useless use of echo” and you could be using ' instead of " arounds some parts so you don’t need so many \, but that’s about it. Shell languages are far from the best way to deal with JSON, but considering that limitation you seem to be handling it well. I’d be more concerned with edge cases and the like. A more robust approach would be to use a language which natively supports JSON (note above how I called osascript -l JavaScript) to handle that part. gingerbeardman 1 Link to comment
gingerbeardman Posted June 16, 2023 Author Share Posted June 16, 2023 Thanks! I'll look into these things and revise. I did already notice it breaks with some game names. Link to comment
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