Jump to content

deanishe

Member
  • Posts

    8,759
  • Joined

  • Last visited

  • Days Won

    522

Everything posted by deanishe

  1. What actually happens is that Google returns each sentence as a separate result, but the workflow throws away all but the first. To get multi-sentence results, open the workflow in Finder and edit the translate script in it to read as follows. This will show all the sentences in a translation. Because Alfred can't show much text in its results, I've added copy text and large type. Hit CMD+C on a result to copy the translation to the clipboard and CMD+L to show the full translation in Alfred's large type window. # Set locale and normalize unicode composition for international support. export LC_CTYPE="UTF-8" query="$(echo "${@:3}" | iconv -s -f UTF-8-Mac -t UTF-8)" # Retrieve and parse Google Translate answer. response="$(curl -G --data-urlencode "text=$query" --data 'client=p' --data 'sl=auto' --data "tl=$1" --silent --user-agent 'Mozilla/5.0' 'http://translate.google.com/translate_a/t' | python -c 'import sys, json; print("".join([d.get("trans", "<UNTRANSLATED>") for d in json.loads(sys.stdin.read())["sentences"]]).encode("utf-8"))')" [[ -z "$response" ]] && translation="No translation found" || translation="$response" # Write feedback. echo '<?xml version="1.0" encoding="UTF-8"?><items> <item uid="translation"> <title><![CDATA['"$translation"']]></title> <arg><![CDATA['"$translation"']]></arg> <text type="copy"><![CDATA['"$translation"']]></text> <text type="largetype"><![CDATA['"$translation"']]></text> <icon>icon.png</icon> <subtitle>”'"$query"'” in '$2'.</subtitle> </item> </items>'
  2. You have added the drive to Alfred's Search Scope in the preferences, haven't you? (Alfred Preferences > Features > Default Results)
  3. That's the way Alfred's designed to work (mixing workflow results and its own results together). You can select "with space" in your Script Filter's options to keep its results out of Alfred's (it won't be run till the query is "kc "). If you want to ensure Alfred's default results aren't mixed in with your workflow's, you need to use a more unique keyword. ".kc" would probably give you no default results in Alfred.
  4. That's not really true. It's perfectly possible to run a background process from within an Alfred script. You just have to be sure that any subprocesses you want to background also disconnect from the parent STDOUT and STDERR, as Alfred won't consider a subprocess finished while one of them is still open.
  5. The problem is your command is the wrong way round. Use cmd 2>&1 >> $log & not cmd & 2>&1 >> $log (with the "backgrounding" ampersand at the end after the redirection). If the ampersand isn't at the end, bash won't background the process, which is why your script isn't exiting immediately.
  6. Thanks, Andreas That only works with URLs (i.e. webservers), not arbitrary hostnames. However, the relevant Python code from that workflow is: import socket def dns_info(hostname): """Return DNS info for hostname""" try: host, aliases, ipaddrs = socket.gethostbyname_ex(hostname) except Exception as err: print('Error fetching DNS for {} : {}'.format(hostname, err)) raise return { 'hostname': host, 'aliases': aliases, 'ipaddrs': ipaddrs } Example output: >>> dns_info('www.google.com') {u'ipaddrs': ['74.125.136.106', '74.125.136.105', '74.125.136.103', '74.125.136.147', '74.125.136.99', '74.125.136.104'], u'hostname': 'www.google.com', u'aliases': []} >>> dns_info('www.yahoo.com') {u'ipaddrs': ['46.228.47.114', '46.228.47.115'], u'hostname': 'fd-fp3.wg1.b.yahoo.com', u'aliases': ['www.yahoo.com']}
  7. I think the only way you could use Alfred's built-in components would be if you used tags or Spotlight comments to add the project name to each 'wp-content' folder. You could try this workflow, which filters across directory levels, so you'd set up a Fuzzy Folder for ~/Sites and then "sites xch wp" (assuming "sites" is the keyword you assigned to ~/Sites) will match ~/Sites/xchange/wp-content/. The best way would probably be to write a Script Filter, however. This is a very rudimentary prototype, but if you use this as a Script Filter (Language = zsh, Escaping = Double Quotes, Backquotes, Dollars, Backslashes), it will do more or less what you want (filter on the project name, open the wp-content folder): #!/usr/bin/env zsh export LC_CTYPE=UTF-8 query="{query}" function projname() { echo "$( echo "$1" | awk -F/ '{print $(NF-1)}' )" } function contains() { local string="${1:l}" local substring="${2:l}" if test "${string#*$substring}" != "$string" then return 0 # $substring is in $string else return 1 # $substring is not in $string fi } wpdirs=(${(f)"$(mdfind -onlyin ~/Sites '(kMDItemContentType == public.folder) && (kMDItemFSName == wp-content)')"}) if [[ -z "$query" ]]; then projects=($wpdirs) else projects=() for p in $wpdirs; do pname="$( projname "$p" )" if contains "$pname" "$query"; then projects+="$p" fi done fi echo '<?xml version="1.0" encoding="utf-8"?>' echo '<items>' for proj in $projects; do pname="$( projname "${proj}" )" cat <<EOF <item valid="yes" type="file"> <title>${pname}</title> <subtitle>${proj}</subtitle> <arg>${proj}</arg> <uid>${proj}</uid> <icon type="fileicon">${proj}</icon> </item> EOF done echo '</items>'
  8. That won't work because /Users/drlulz/Documents/anki isn't part of your $PATH… Either use the full path to runanki or cd to ~/Documents/anki first and do env -i ./runanki. You are actually using the full path to the runanki executable in your workflow script, aren't you?
  9. It could be lots of things. Try running the program with env -i runanki to simulate the empty environment.
  10. That works, of course, but you kind of have to Alfred before you can Alfred if you know what I mean.
  11. It doesn't work for me because it can't find requests. When you distribute your workflow, you should consider including any libraries it needs with it. You can install them in your workflow using, e.g., pip install --target=/path/to/my/workflow requests.
  12. The reason you can't figure it out is because it's almost impossible to do in the way you're thinking. There's absolutely no way for Alfred to look directly into browser tab. Pretty much the only thing a browser will tell an external program is the URL and titles of its tabs. If you need to work with the contents of browser windows, what you need is a userscript or browser extension. Probably this one.
  13. Perhaps consider using iTerm 2 instead of Terminal? It's better and has a visor mode built in (you need the nightly build, though).
  14. That can all be done from a workflow, but you'd need to do some coding with a library like mechanize to handle the authentication.
  15. I think he wants Alfred to be triggered by received mail. Basically, Mail.app is probably the simplest way to do this. There are lighter-weight alternatives, but they're much more complex to achieve. As I understand it, you want to trigger Alfred actions on one machine from another via email. So on the receiving end, you need something that can talk to a mailserver or your email client and to Alfred. There aren't many email clients that can run scripts from filters, and writing your own client is a bit tricky. If you use Gmail, you could perhaps whip something up with the API.
  16. It strikes me as an odd thing to want to do, but it can sort of be done. You could create a workflow with a Keyword attached to an Open URL action (with URL set to {query}). Assign the CMD+L hotkey to the keyword, and then hitting CMD+L will open Alfred's action-specific window, which will only show results from that specific workflow (which in this case is none). The issue with this is you need to enter valid URLs (i.e. with http:// or https://). I suppose you could replace the Open URL action with a Run Script action and the bash script: open "http://{query}"
  17. There's a bug in the code. You're calling wf.send_feedback() in search(), but you also call it in prepare_feedback() if there's an error. So when the workflow wants to display an error, it wrongly outputs the XML twice.
  18. You shouldn't really alter the Info.plist file of existing apps because it invalidates the signature. What exactly do you mean by "toggle [your] terminal"?
  19. I didn't know KM has a run-on-wake feature (probably could have guessed, though. It has every feature.) Handy to know. Doesn't ControlPlane need to be running all the time to do its thing?
  20. Are you two both using Yosemite? It seems that launchd also has some issues on Yosemite. Are your other Launch Agents working correctly?
  21. Thanks. I'll be glad to hear if it's working. I'm at a bit of a loss here: launchd is explicitly designed to run missed jobs on wake. I'll try and replicate the problem on my notebook. I can't sleep my main machine, as the network doesn't come back up on wake (thanks, Yosemite!) If you unload and reload the Launch Agent, does it run correctly then? As a stop-gap, you could try using SleepWatcher to unload and reload the Launch Agent on wake. That should make the script run with your desired settings.
  22. I've added a wrapper script to the Gist. You can put all your settings in there, so you can update the Python script without having to edit it every time. The wrapper should go in the same directory as the Python script and you should run the script via the wrapper instead. The Launch Agent will still call the Python script, but any settings from the wrapper will be preserved.
  23. What do the log files say? Did launchd actually try to run the Launch Agent on wake?
  24. Did it work? The themes have changed because I changed the defaults.
×
×
  • Create New...