Jump to content

rice.shawn

Member
  • Posts

    973
  • Joined

  • Last visited

  • Days Won

    57

Everything posted by rice.shawn

  1. Packal tries a number of ways to ping Google to check to see if there is an active Internet connection. If there isn't one, then it offers different options. It should also try to reach out to Github because Packal pushes its archive onto GH. But there is nothing in the code that would make it try to reach the Android Marketplace or maps.google.com. My only guesses are that your firewall is misidentifying the google homepage with either of those based on IPs (this is just a thought) or that another service is hitting those at a similar time because there is nothing in the code that reaches to either of those places.
  2. Another option, if you want to make a blank Word document without opening Word, then you could just use Bash touch ~/Desktop/test.docx
  3. I'm stoked that you put in support for Mopidy. I hate the Spotfy app, and Mopidy + this workflow is a much better way to make it all work.
  4. Rafaele, The simplest fix to do this is to open the workflow and just replace every instance of the word "Safari" with "Google Chrome" If that doesn't work, then change tell window 1 to set current tab to (make new tab with properties {URL:theURL}) To open location theURL
  5. Sorry, I had to run earlier, hence the short explanation. The workflow that I uploaded (dropbox link), is a simple implementation. I wrote it in PHP using my Alphred library. Let me take you through it. The script filter is just a few lines: <?php require_once( __DIR__ . '/Alphred.phar' ); $workflow = new Alphred([ 'error_on_empty' => true ]); $sites = json_decode( file_get_contents( __DIR__ . '/sites.json' ), true ); if ( isset( $argv[1] ) ) { $sites = $workflow->filter( $sites, trim( $argv[1] ), 'name' ); } foreach ( $sites as $site ) : $workflow->add_result([ 'title' => 'Open ' . $site['name'], 'subtitle' => $site['url'], 'arg' => $site['url'] ]); endforeach; $workflow->to_xml(); And the sample JSON file that I used: [ { "name": "Google", "url": "http://www.google.com" }, { "name": "Packal", "url": "http://www.packal.org" } ] Let me take you through it. The $workflow->filter is part of the Alphred library, and it just filters out anything that doesn't match what you've typed into the query ($argv[1] is the query). Then, the foreach loop just cycles through all of the items that are defined in the JSON file and displays what matches (or displays all if there is no query). As an added bonus, the $workflow->filter will also sort the results so the matches will be sorted via best and descending. The $workflow->add_result just adds an item to what will be the script filter. The key part is that the `arg` is the url. This works because the workflow is setup so that the script filter leads to an "Open URL" action. You can add more items to the JSON file by replicating the same structure. Just note, however, that JSON can get a bit finicky. If you open the sites.json file with TextEdit, make sure that you're using plain text because TextEdit will try to convert the quotation marks to smart quotes, which will break the JSON file. Also, make sure that the commas are in the correct places; otherwise, the JSON will break. Does this accomplish what you need, and do you see how you can expand it?
  6. Here's the simplest way to do it: https://www.dropbox.com/s/vr8mix8k6leao3q/Custom%20Bookmarks.alfredworkflow?dl=0. There's a simple script filter created there, and it leads to an "Open URL" action. The sites are defined in a simple JSON file that's in the workflow directory.
  7. Does it actually not continue or does the NSAppleScript action somehow not work? You can test this by doing some sort of log function in the second action (i.e. write to a file, write to STDERR, etc...). If it always gets there but works intermittently, then the problem is with that action. Otherwise, there might be a problem where it's choking on the text in the argument. You might consider finding ways to escape everything. I generally stay away from the NSAppleScript actions in favor of osascript. If the above doesn't work, then try switching to osascript.
  8. Well, I just fixed mine. Thanks for the leads.
  9. Updated to version 1.1. Fixed a bug where the translation would show only one sentence, even if more than one was typed. Bug was reported in Florian's similar workflow, and it applied to this one as well. Find the update on Packal. Or just use the Packal updater.
  10. The Robtex thing doesn't really show subdomains. But, I guess that you could try to get more information by finding starting with Robtex and then finding and parsing the zone file for each of those domains...
  11. That's how we all start. It seems that the most common development pattern, for simple workflows, is to throw everything into a single script filter, and one that does more to guess what the user wants. Having as few keywords is a good thing to do, especially when people start installing 100+ workflows (like me..., and Dean), so that there are fewer to remember. Really complex ones (think the Evernote workflow, the Spotify Workflows, ZotQuery) have multiple ones for really good reasons. There is no straightforward tool to do so, but it looks like you can find something with Robtex.com. Check out this example (https://www.robtex.com/en/advisory/ip/162/243/215/240/), which is a redirect for (https://www.robtex.com/ip/162.243.215.240). There's also an API, but I haven't looked into it too much.
  12. I was just working on this, and, well, I took the other route to make the json valid. Basically, it seems that for a null value, Google just sends back nothing, so I added a while loop to look for two commas in a row and replace them with `,null,`. But your solution seems much, much better.
  13. You know, I noticed this when I was writing my version of this workflow, but I lost track / got distracted and forgot to continue looking into it. I should go fix mine.
  14. You could also just use a single script filter to route it in case the user does what Dean does and (un)intentionally breaks it. So, here's some untested Ruby code: query = ARGV[0].downcase if ARGV.length > 0 query.strip! if /[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}/.match(query) /usr/bin/ruby __dir__/ip_lookup.rb query else /usr/bin/ruby __dir__/whois.rb query end Or, you could use a more complex regex that actually checks to make sure that the ip is in range: query = ARGV[0].downcase if ARGV.length > 0 query.strip! regex = RegEx.compile('^(??:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)^(??:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$#46;){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$') if query.match regex /usr/bin/ruby __dir__/ip_lookup.rb query else /usr/bin/ruby __dir__/whois.rb query end But, you should double-check these because they're untested (and because my head hasn't been in Ruby recently). But the logic is solid: check if the user is inputting an IP address; if so, use the ip script; if not, use the whois script.
  15. Apple has a nice utility to do this with Wifi connections, but there is no utility to do it with bluetooth connections. You can list devices with the blued command, but it doesn't allow you to connect / disconnect. LightBlue is a python library for OS X to interact with bluetooth connections, but it was written for 10.8 and hasn't been updated in two years. Some people might be able to get it to compile on Yosemite by following the suggestions in this issue. I haven't tried to install it on Yosemite. As I mentioned in the previous post, you can do this with UI scripting, but UI scripting is awful and not necessarily reliable. But, from everything that I've read, it's the only way to get it done. Look, again, at my previous post for a link with a sample script that will do the UI scripting for you. But there is no elegant way to accomplish this with a script filter that would check the individual devices on your computer.
  16. Two options: nslookup "{query}"|grep Address:|grep -v \#|head -n 1|sed 's|Address: ||g' or ping -c 1 "{query}"|grep PING|sed -E 's|.*\(([0-9.]*)\).*|\1|g' "{query}" is obviously the website to look up. The output for both commands will be the IP address. Caveat: if you try this with a bad host (my test case was the word "cheese"), then you get an IP for the nslookup, but with ping you get "ping: cannot resolve cheese: Unknown host"
  17. Actually, nevermind. Use wrap the command around `ping` or something else that gives you the output.
  18. Find a whois service that has a public API that you can use. Then, pick your language (probably PHP, Python, or Ruby because of their ability to handle the probably JSON that the API will send back), and wire up the appropriate Alfred library. Adding in some URL validation would probably help.
  19. Here's a quick way to search Google Books: Download it from Packal. It grabs some book images for you in the background so that searches will features them, although image downloading is pushed to the background so it doesn't slow down the script filter. It caches searches for a month (which seems reasonable for Google books), so subsequent searches are prety quick. Selecting a result will open the Google books page. I needed this for my own use, and so, using Alphred, I wrote in in less than the time that I took to drink a beer, but I figured that others might enjoy using it, so I'm sharing it here. I'm open to feature requests. Cheers.
  20. You'll need to create a workflow that uses AppleScript. Look at this thread for some sample code.
  21. This isn't helpful, but the title of the post makes me want to tell you to check under your couch cushions. That's where I always lose mine.
  22. Well, `osadecompile` doesn't help because it gives you the exact text that you typed in (I was curious if it would). What's hilarious is that this code works: osascript -e "$(osadecompile test2.scpt)" But, of course, that's just dumb. But, the source of the problem is that, when compiled, "state" is not returned as a string (even though you request it as one). When I try this code: #!/usr/bin/osascript tell application "iTunes" set state to (get player state as string) as string if state is "playing" then do shell script "echo is playing: " & state pause else do shell script "echo not playing: " & state end if end tell Then, when playing, I get "not playing: «constant ****kPSP»", and when it is not playing, I get "not playing: «constant ****kPSp»". So, the difference is the big v little p at the end of the constant, but the problem is that it is a constant and not a string. The actual fix is the following: if application "iTunes" is running then tell application "iTunes" if player state is playing then pause end tell end if In other words, if you don't try to make it into a string, then it just works. (Both from the command line and from the script editor).
  23. I just looked up that app, and it seems neat. But the approach to creating something like (from the bit that I read) seems incompatible with most of the work that is done with Alfred workflows. The main reason is that the iOS app seems to need the applications themselves to have either coded in actions or the iOS workflows app provides the actions, and these, for the most part, need to be written and compiled with Objective-C (or Swift) and rely mostly on iOS URI schemes and callbacks to make everything work. Workflows for Alfred are coded with scripting languages (AppleScript, Bash, Perl, PHP, Python, Ruby, Zsh, etc...), which are not available in the same way, if at all, on iOS. So while the functionality might be the same, the approach to implementing them is not cross-compatible, thus not portable.
  24. It works just fine for me from bash. All I did was copy/paste the snippet in the OP into a file called test.scpt. I opened iTunes, pressed play on the first track (which, apparently is a Ke$ha track... don't ask). Then, in iTerm I entered the command `osacript test.scpt`, and iTunes paused just fine. But, let's get a bit more specific. To create the script, I did `nano test.scpt` from in iTerm and copy/pasted there. As a curiosity, I tried it again by saving it through Script Editor as `test2.scpt`. The script would work correctly when run from Script Editor, but it wouldn't work via the Bash command. So I can reproduce your problem that way. So there has to be a problem with the way that Script Editor is saving that particular script. When I `cat test.scpt`, then I see the script. When I `cat test2.scpt`, then I get the binary version of the script (garbled text). The size difference is staff 1952 Mar 4 11:45 test2.scpt staff 163 Mar 4 11:35 test.scpt So, 163 bytes vs 2kb. Weird, right? So, I propose a work around: save the script as plain text rather than as a compiled binary script file. While the latter should work, something is making it not work.
  25. The Packal caches just need some time to clear out. The page is cached in whole and in parts, so it takes a little while for all of them to update.
×
×
  • Create New...