Jump to content

deanishe

Member
  • Posts

    8,759
  • Joined

  • Last visited

  • Days Won

    522

Everything posted by deanishe

  1. This Python script will print one of the sentences at random when run. Put it in a Run Script Action with Language = /usr/bin/python. SENTENCES = """\ 12 Drummers Drumming 11 Pipers Piping 10 Lords a-Leaping 9 Ladies Dancing 8 Maids a-Milking 7 Swans a-Swimming 6 Geese a-Laying 5 Gold Rings 4 Calling Birds 3 French Hens 2 Turtle Doves 1 Partridge in a Pear Tree """ import random sentences = [s.strip() for s in SENTENCES.split('\n') if s.strip()] print random.SystemRandom().choice(sentences) Connect the Run Script Action to a Copy to Clipboard Output (possibly selecting "Automatically paste to front most app").
  2. You should probably remove those directories from Alfred's default Search Scope. That should be kept fairly small. Use the File Search (start your query with a space) to find normal files. Basically, you're stuck with Spotlight's database. Alfred doesn't work well with system files (I couldn't get a File Filter to work with files in ~/Library/Logs). Spotlight does index /etc and the like. The command-line tool mdfind works on /etc or ~/Library just fine, as do Finder search and Smart Folders. The only way to explicitly exclude files, other than using Spotlight's Privacy pane, is to tag them with alfred:ignore. Unfortunately, you have to tag each individual file: tagging a directory will hide the directory, but not its contents.
  3. The API is simple enough. You can get the names and IDs of cities via the autocomplete API: http://www.numbeo.com/common/CitySearchJson?term=london This returns JSON: [ { "label": "East London, South Africa", "value": "1683" }, { "label": "London, Canada", "value": "2352" }, { "label": "London, United Kingdom", "value": "6512" }, { "label": "London, KY, United States", "value": "9196" }, { "label": "Londonderry, United Kingdom", "value": "6513" } ] Then pass two of those ID numbers to this URL: http://www.numbeo.com/common/dispatcher.jsp?city_id1=1683&city_id2=6512 At this point, you can either take the easy route of opening that URL in the browser, or the harder route of extracting data from the HTML to show in Alfred.
  4. It's fairly simple to do the Finder part in AppleScript by simulating a ⌘+T keypress: set thePath to "/Users/me/Desktop" tell application "System Events" tell application process "Finder" to set frontmost to true keystroke "t" using command down end tell tell application "Finder" to set target of front window to (POSIX file thePath) as alias This opens the specified path in a new window if none exists, and a new tab if there is one.
  5. You can do a lot with iTunes via AppleScript. You could connect Hotkeys to Run Script actions with some of these: -- start playback tell application "iTunes" to play -- stop playback tell application "iTunes" to pause -- toggle play/pause tell application "iTunes" to playpause -- play previous track tell application "iTunes" to previous track -- play next track tell application "iTunes" to next track -- turn volume up by 10% tell application "iTunes" to set (its sound volume) to (its sound volume) + 10 -- turn volume down by 10% tell application "iTunes" to set (its sound volume) to (its sound volume) - 10 -- toggle mute on/off tell application "iTunes" if (its mute) then set (its mute) to false else set (its mute) to true end if end tell
  6. I'm not sure if there is a specific explanation of {query}. Essentially, {query} is a text macro used by Alfred to pass input to your scripts. When it runs your code, Alfred first replaces all occurrences of {query} with whatever the input to the script is. The input may be text entered by the user in Alfred's query box, the argument from a Script Filter result, or the STDOUT output from another script (i.e. what the script outputs with echo or print). The only exception is Run NSAppleScript. Because these are loaded and run within Alfred, it can give you the input as an actual variable (instead of doing search/replace on your source code before running it), which is the q in on alfred_script(q) So in your example, you don't need {query}. If you're running the script with a Run NSAppleScript Action, put your code in the on alfred_script(q) … end alfred_script function and q is your query. However, if you're using a normal Run Script Action (or a Script Filter), these are run outside Alfred by whatever program you specify, and you need to use the set theQuery to "{query}" text macro to get the input. on alfred_script(q) is a special function that is called when you run an AppleScript with Alfred's Run NSAppleScript Action. The equivalent function when run any other way (in Script Editor, Automator, with osascript etc.) is run() So, the following version of your code will run either as a Script Filter/Run Script (where run() is called) or as an NSAppleScript (where alfred_script() is called): on run (argv) set theDelay to "{query}" as integer return my pauseITunes(theDelay) end run on alfred_script(q) set theDelay to q as integer return my pauseITunes(theDelay) end alfred_script on pauseITunes(theDelay) tell application "iTunes" pause delay theDelay play end tell end pauseITunes
  7. What does the script do when you run it in a shell? What about using env -i ./myscript.sh to simulate Alfred's empty environment?
  8. Connect your File Filter to an Open File Action and a Reveal File in Finder Action. Double-click the lines connecting your File Filter to one of the actions and set a modifier key, e.g. ⌘. This action will then be performed when you hit ⌘+↩ on a result. If you're happy with Open File being the default action, just use a single Open File Action. Alfred's default behaviour with results that are files is to make Reveal in Finder the default ⌘+↩ action.
  9. Escaping tells Alfred which characters need to be escaped, i.e. preceded with a backslash. Alfred's defaults for any given language are correct (but don't change the quotes around {query}!) When it replaces {query}, Alfred basically rewrites your script before running it. If there's something in {query} that would break the script or command or make it invalid, it needs to be escaped. If you have this script to copy a file to your desktop: cp {query} ~/Desktop and the provided input is Some File.txt, Alfred will replace {query} with it and run: cp Some File.txt ~/Desktop which will break because this command says "copy Some and File.txt to ~/Desktop" (the space delimits arguments). As a result, you instead use "{query}" (in quotes), so Alfred runs: cp "Some File.txt" ~/Desktop which is correct. In turn, this would break if {query} contained a double quote, e.g. Say, "hello!", as Alfred would expand "{query}" to "Say, "hello!"", closing the quotes and inserting the literal hello!, which the program would interpret as a command or variable, and break. So, you escape Double Quotes and Alfred instead expands "{query}" to "Say, \"hello!\"", which is once again a valid string. Finally, some languages do some extra processing of strings in double quotes. Certain escapes, like \n and \t, are expanded to newline and tab respectively. So you need to also escape Backslashes to prevent \n becoming a newline. Also, some languages, like PHP and bash, try to expand variables in double-quoted strings, e.g. in echo "Dear $name", they will replace the variable $name with its value (or nothing), so you need to escape Dollar, too. This kind of input may seem odd, but it's common enough for, say, a search engine workflow. If you just want to pass the user's query to your script, you should stick with the defaults for the language you're using. The only other meaningful configuration is escaping off, so you can compose your own commands in {query}. Anything other than defaults or off is probably broken in some way.
  10. You can just use /usr/local/bin/ru {query} Is there a reason you aren't using the default settings and escaping options?
  11. It's almost impossible to say without the code and the input/output that's causing the problem.
  12. This isn't really how you'd go about implementing this. If you're using a lot of almost-identical scripts, write one script that can handle the different input and save it in your workflow's directory. Then call that script from your Run Script actions, e.g. osascript myscript.scpt name "{query}" If you want to write nested keywords (sc > lua > ...), a Script Filter is the best way if you have a lot of keywords. You can pass as much or as little data as you want via {query}, but this sometimes means parsing the input yourself. There isn't a Reveal in Terminal action. Here's one: on run (argv) set thePath to first item of argv openTerminalAtPath(thePath) end run on alfred_script(q) openTerminalAtPath(q) end alfred_script on openTerminalAtPath(thePath) tell application "Terminal" activate tell application "System Events" to keystroke "t" using command down repeat while contents of selected tab of window 1 starts with linefeed delay 0.01 end repeat do script "cd " & quoted form of thePath & " && clear" in window 1 end tell end openTerminalAtPath
  13. You don't need the clipboard for this. You can pass the URL straight to TextEdit. This shows you how to create and save TextEdit documents: -- Called when script is executed on run (argv) -- Base name of the document without directory or file extension -- e.g. "Important Stuff" set documentName to "My Document" -- Where to save new files. Default is ~/Documents set saveDirectory to (path to documents folder) -- Make sure this is something TextEdit understands, e.g. ".rtf", ".txt" set fileExtension to ".rtf" set theText to my getSafariUrl() set thePath to my newFilePath(documentName, saveDirectory, fileExtension) createTextEditDocument(thePath, theText) end run -- Create a new document containing `theText` and save it at `thePath` on createTextEditDocument(thePath, theText) tell application "TextEdit" activate make new document with properties {text:theText} save document 1 in file thePath end tell end createTextEditDocument -- Return the URL of Safari's current tab on getSafariUrl() tell application "Safari" to return URL of front document end getSafariUrl -- Return an unused filepath by appending 1,2,3 etc. to `documentName` on newFilePath(documentName, saveDirectory, fileExtension) set theSuffix to 1 tell application "Finder" set fileName to (documentName as text) & fileExtension set thePath to (saveDirectory as text) & fileName repeat while item (thePath) exists set fileName to (documentName as text) & " " & (theSuffix as text) & fileExtension set thePath to (saveDirectory as text) & fileName set theSuffix to theSuffix + 1 end repeat end tell return thePath end newFilePath
  14. You can do this with a workflow easily enough. Keyword -> Run Script -> Open URL. URLs can be manipulated much more powerfully in Python or Ruby than via some additional options in the Web Search dialog. Here are a few examples in Python: from urlparse import urlsplit, urlunsplit url = "{query}" parsed = urlsplit(url) # Domain print(parsed.netloc) # Without scheme:// print(urlunsplit(('',) + parsed[1:]).lstrip('/')) # Hostname print(parsed.hostname) # Resolve URL redirects / Expand shortened URLs import urllib2 print(urllib2.urlopen(url).geturl())
  15. AppleScript is weird, and behaves differently when run in different ways. If you're using a Run NSAppleScript action, try using a normal Run Script action with Language = "osascript (AS)" instead. You can also try saving the script in the workflow directory and running it via bash : osascript myscript.scpt
  16. Try renaming your Igor Pro file. This should cause Spotlight to re-import it. Then drag it to the File Types box again. If you still get "dyn.XXXXX", then it looks like the filetype hasn't been registered. You can re-register apps, rebuild and dump the filetypes with lsregister.
  17. The reasonable solution is to use a more sensible hotkey for Alfred. When you simulate keypresses (by typing from the clipboard), applications literally can't tell the difference between that and real keyboard input, so two uppercase letters results in Alfred registering two ⇧ presses. That is to say, Alfred is behaving correctly in accordance with the (inadvisable) way you've configured it. So fundamentally, the cause of the problem is a bad choice of hotkey. ⇧ and ⌥ are often used for inputting text, so you shouldn't use them for global hotkeys (except with F-keys) unless combined with ⌘, ^ or fn (which aren't used for text input). If you change the hotkey to double-tap ^ or ⌘, you shouldn't have the issue.
  18. FWIW, the API is cheap as chips. I run scores of pages through it every month, and it costs a couple of euros at most.
  19. This isn't a bug. It's literally the behaviour you're explicitly requesting by using a Run NSAppleScript Action. That is to say, Run NSAppleScript means "run this AppleScript in Alfred". If you want Alfred to bugger off out the way when you run your script, use a normal Run Script Action instead (with Language=/usr/bin/osascript (AS)). Be sure to remove the on alfred_script(q) + end alfred_script wrapper around your script.
  20. Yet you still ended your last comment with three periods, not an ellipsis… But seriously, any time you see dot-dot-dot in OS X, it's almost certainly a single ellipsis, not three dots.
  21. FWIW, the original name I proposed didn't contain 3 periods, but 1 ellipsis (the dot, dot, dot character). I think this is OPT+; on an English keyboard (I have a German keyboard). Alternatively, you could copy the character I posted. Actions with dot-dot-dot at the end of their name typically contain an ellipsis, not three periods, i.e. one character, not three, and you won't have issues with the OS stripping a character.
  22. Alfred uses the Spotlight metadata database for its searches. Enabling Spotlight support on BoxCryptor volumes should also make the files visible to Alfred. You may still have to add the volume to Alfred's search scope, depending on where you want the results to show up. You should also add the encrypted folders to the list in Spotlight's Privacy tab, so the encrypted files don't show up in your results.
  23. You just need to drag and drop an Igor Pro file into the File Types box.
×
×
  • Create New...