Jump to content

dfay

Member
  • Posts

    1,054
  • Joined

  • Last visited

  • Days Won

    62

Reputation Activity

  1. Like
    dfay got a reaction from winterflags in Exclude Workflow from Dropbox Sync   
    You can use Applescript to write a workflow that behaves differently depending on which computer it's running on.  Basically you'd set your hotkey to call an Applescript like this:
     
    set theComp to computer name of (system info) if theComp = "computer A" then // do something else if theComp = "computer B" then return end if  
  2. Like
    dfay reacted to deanishe in Allow workflow editor window to scroll beyond bottom   
    Currently, if a workflow extends beyond the bottom of the editor window in Alfred Preferences, it's only possible to scroll as far down as the bottom edge of the lowest element.
     
    This makes it mildly tricky to add an element beneath that (i.e. start a new row). You have to create it somewhere in the middle of your existing elements, then drag it down into position.
     
    It'd be helpful if Alfred allowed you to scroll down about a row's worth of pixels beyond the bottom of the lowest element, so you can create elements where you want them.
     
    It's a fairly minor thing, but if it's easy to implement, I think it would improve the workflow-building experience a wee bit.
  3. Like
    dfay got a reaction from deanishe in Running AppleScript unintentionally reopens Alfred bar efter closing   
    Are you using option-space as your hotkey for Alfred?  The script is trying to get Evernote to do something by simulating an option-space keypress in System Events.
  4. Like
    dfay got a reaction from switters in Migrate Alfred settings/snippets after clean install of OS X?   
    I should know since I did this three times in the past year.... as I recall I just pointed the new installation at the existing sync folder on dropbox (obviously you need to reinstall the dropbox client first and let it finish syncing). I'd make a backup first and just try that. I certainly don't recall any problems or needing to do any additional configuration.
  5. Like
    dfay reacted to winterflags in Running AppleScript unintentionally reopens Alfred bar efter closing   
    Keen observation! That solved my problem, thanks.
    Funny coincidence that they were using the same key combination, so I changed the one used in Evernote.
  6. Like
    dfay got a reaction from switters in Workflow help: Search for clipboard contents in Google?   
    By the way....if you don't have it already, this is invaluable:
     
    http://www.alfredforum.com/topic/2224-reference-importer/?hl=%2Breference+%2Bimporter
  7. Like
    dfay reacted to switters in Workflow help: Search for clipboard contents in Google?   
    Wait! I figured it out. Thanks for the suggestion. 
  8. Like
    dfay reacted to nikivi in Make conditional statement in Alfred Help   
    Thank you all for help. I have made it work with having this script be run right after the hotkey trigger : 
     

  9. Like
    dfay reacted to deanishe in Clipboard as input in Python script?   
    It's not completely arbitrary because Alfred can't include everything and this is very, very easy to do.
    Add a Run Script Action Set Language to /bin/bash Put the following in the Script box: pbpaste You now have a Clipboard Contents Input.
     
    Getting the clipboard contents in Python: 
    import subprocess   def get_clipboard():     """Return clipboard contents as Unicode."""     s = subprocess.check_output(['pbpaste'])     return s.decode('utf-8')
  10. Like
    dfay reacted to deanishe in How do I add Safari history to default search results?   
    Yup! I've been digging into this for a Safari workflow I'm working on.

    It stores a whole bunch (many thousands) of .webhistory files in ~/Library/Caches/Metadata/Safari/History
     
    Drag one of those to a File Filter to search your Safari history. I wouldn't recommend adding your history to your default scope, as the entries might overwhelm your other results.
     
    The UTI is com.apple.safari.history
     
    Safari also exports its bookmarks (to ~/Library/Caches/Metadata/Safari/Bookmarks with the extension .webbookmark and UTI com.apple.safari.bookmark).
     
     
    OmniFocus also exports its metadata to files under ~/Library/Caches/Metadata. I hope this is something a lot of apps start doing. It's very handy.
  11. Like
    dfay reacted to deerawan in Material Design Theme Alfred V3 - 13 Themes to Choose!   
    Material Design Theme 
     
    For Material Design lovers 
     
    Note: I have not tested it yet on Alfred 2
     
    Download All Themes
    https://goo.gl/3g9uef
     
    Download Single Theme
    Click the download link below the theme name Save as the file (keep the extension to be .alfredappeareance)  
    Light Themes
     
    Material Tosca
     
    Download
    https://goo.gl/Zfq1oy
     

     
     
    Material Purple
     
    Download
    https://goo.gl/Keffj2
     

     
     
    Material Green
     
    Download
    https://goo.gl/x46hAh
     

     
    Material Blue Grey
     
    Download
    https://goo.gl/7hJEuA
     

     
    Material Brown
     
    Download
    https://goo.gl/UJT1TG
     

     
     
    Material Red
     
    Download
    https://goo.gl/BzS657
     

     
     
    Material Blue
     
    Download
    https://goo.gl/rbrnZ5
     

     
     
    Material Yellow
     
    Download
    https://goo.gl/NgvVna
     

     
    Material Pink
     
    Download
    https://goo.gl/CKB8M1
     

     
     
    Dark Themes
     
    Material Tosca Dark
     
    Download
    https://goo.gl/rjY8NF
     

     
    Material Blue Dark
     
    Download
    https://goo.gl/ZepPZ9
     

     
     
    Material Blue Grey Dark
     
    Download
    https://goo.gl/sjeNPD
     

     
     
    Material Red Dark
     
    Download
    https://goo.gl/mjHefJ
     

     
    Hope you like it!
  12. Like
    dfay reacted to Stephen_C in Search Postbox 4 emails from Alfred?   
    Yes...undoubtedly! However as:
    I am a beginner with Alfred; and I don't really need the workflow I seem to have developed I may leave that for the moment. Nevertheless, I'd not have got this far without your help—which is much appreciated.
     
    Stephen
  13. Like
    dfay got a reaction from nikivi in open Alfred Preferences to last workflow run   
    Often I run a workflow and then immediately think of something I should add to it.  It would be great to have a way to have a keyword or hotkey that would immediate Alfred's preferences open to the last workflow I ran.
     
     
  14. Like
    dfay reacted to rogierl in Add specific file type (in this case: markdown)   
    This fixed it! So I did:
     
    Removed entry from user defined file types in Alfred Rebuild launch services with command below Add a markdown file (with extension .md) /System/Library/Frameworks/CoreServices.framework/Versions/A/Frameworks/LaunchServices.framework/Versions/A/Support/lsregister -kill -r -domain local -domain user
     
    Thanks!!!
  15. Like
    dfay got a reaction from csaborio in Apple Music Workflow to add Current Song to Playlist   
    nah I don't think it's possible - if Doug Adams doesn't have a script for it, you can pretty much assume it can't be done yet.  In Sierra maybe.
  16. Like
    dfay got a reaction from gammawert in Creating recursive date-output (%y%m%d)   
    You should use a Run Script object instead of Terminal Command.
     
    Alternatively you can do this without a workflow at all using a snippet with dynamic placeholders - see https://www.alfredapp.com/help/features/clipboard/dynamic-placeholders/
  17. Like
    dfay got a reaction from erravid in Open app in background   
    It would be great to be able to hold a modifier key when opening an app from Alfred, and have it open in the background without stealing focus.
     
    This can be done from the command line with 
     
    open -g path/to/app
     
    and I could create workflows for each of my commonly used apps to allow this....but it would be great as a built-in feature.
  18. Like
    dfay reacted to deanishe in Handling workflow/environment variables   
    Note: This post is out of date as of Alfred 3.6 (which introduced AppleScript functions to set and remove variables).

    There is an updated version on my own site: Workflow/environment variables in Alfred.

    This post will not be updated due to the difficulty of editing complex posts using the forum software. Sorry.
     
     
    This is a brief look at how to get, set and save variables in code (i.e. in Script Filters, Run Script Actions, etc.).

    In Alfred 2, you had one single variable to work with: the {query} macro. Alfred 3 adds the ability to specify as many variables as you want. Alfred's own help provides a great description of working with variables in Alfred's own UI. I'm going to look more closely about getting and setting workflow/environment variables in your own code within a workflow.

    First of all, it bears mentioning that all variables are strings. Sure, you can set a variable to a number in JSON, but when it reaches your next script or one of Alfred's Filter Utilities, it will be a string. If you set a variable to an array (e.g. [1, 2, 3, "mach dat Mäh mal ei"]), Alfred will turn it into a single, tab-delimited string ("1\t2\t3\tmach dat Mäh mal ei").

    Setting variables

    There are several ways to set variables. The most obvious ones are in the Workflow Environment Variables table in the workflow configuration sheet and using the Arg and Vars Utility. The configuration sheet is largely without magic, but in an Args and Vars Utility, you can use variable expansion macros: {query} expands (as always) to the input (which may be a user-entered query or the output from a previous Action), and you can use {var:VARIABLE_NAME} macros for your own custom variables.  This is described in detail in the above-mentioned help pages.

    More interestingly, you can also set variables via the output of your scripts (i.e. dynamically) by emitting appropriate JSON. How you set variables depends on whether you are using a Script Filter or a Run Script action.

    You must use the appropriate mechanism, or it won't work.

    From Run Script actions

    Let's say your script outputs a URL, e.g. https://www.google.com. Normally you just do print('https://www.google.com') (or echo or puts) and that gets passed as the input to the next action. To also pass variables, you instead emit JSON in a very specific format:
    {"alfredworkflow": {     "arg": "https://www.google.com",     "variables": {"browser": "Google Chrome"}}} The root alfredworkflow object is required. If it's missing, Alfred won't parse the JSON, but will pass it as-is as input to the next action (which can also be very useful). Your output (i.e. the next Action's input/{query}) goes in arg, and any variables you wish to set go in the variables object.

    From Script Filters

    You can also set workflow variables via Script Filter feedback at three different levels: the root level, the item level and the modifier level. (Note: This only applies to JSON feedback; XML feedback is now deprecated and does not support the features described here.)

    In each case, variables are set via a variables object at the appropriate level (feedback root, item or mod).

    Root-level variables

    Root-level variables are always passed to downstream elements regardless of which item is actioned. They are also passed back to the same Script Filter if you've set rerun, so you can use root-level variables to implement a progress bar.

    browser is set to Safari for all items:
    {"variables": {"browser": "Safari"},  "items": [{"title": "Google",    "arg": "https://www.google.com"}]}
    Item-level variables

    Item-level variables are only passed downstream when the item they're set on is actioned, and they override root-level variables. Root-level variables are also passed downstream when you action an item.

    browser is set to Safari by default, but Google Chrome for Reddit:
    {"variables": {"browser": "Safari"},  "items": [    {"title": "Google",      "arg": "https://www.google.com"},    {"title": "Reddit",      "arg": "https://reddit.com",      "variables": {"browser": "Google Chrome"}}]}
    Modifier-level variables

    Modifier-level variables are only passed downstream when the corresponding item is actioned with the appropriate modifier key pressed. They replace item- and root-level variables (i.e. if a modifier sets any variables, Alfred ignores any root- and item-level variables).

    As above, browser is set to Safari by default and Google Chrome for Reddit. But you can also pass browser=Google Chrome for Google by holding ⌘ when actioning it:
    {"variables": {"browser": "Safari"},  "items": [    {"title": "Google",      "arg": "https://www.google.com",      "mods" {"cmd": {"variables": {"browser": "Google Chrome"}}}},    {"title": "Reddit",      "arg": "https://reddit.com",      "variables": {"browser": "Google Chrome"}}]}
    Using variables

    So you've set a few variables, and now you want to use them. Within Alfred elements like Arg and Vars or Filter Utilities, you use the above-mentioned {var:VARIABLE_NAME} macros. Very simple.

    Where it gets a little more complicated is in your own code. First and foremost, {var:VARIABLE_NAME} macro expansion does not work in Run Script Actions (or Run NSAppleScript).

    When Alfred runs your code, it does not use {var:...} macros, but rather takes any workflow variables and sets them as environment variables for your script. Using the above example again, Alfred would pass "https://www.google.com" to my script as input (either via ARGV or {query} depending on the settings) and it would set the environment variable browser to Safari or Google Chrome. How you retrieve environment variables depends on the language you're using.

    Accessing environment variables in different languages

    In bash/zsh, the variables are already in the global namespace. Just use $browser

    In Python, use the os.environ dictionary or os.getenv('VARIABLE_NAME'):
    import os browser = os.environ['browser'] # Or browser = os.getenv('browser')
    In AppleScript, use system attribute:
    set theBrowser to (system attribute "browser")
    In JavaScript (JXA), use $.getenv():
    ObjC.import('stdlib') var browser = $.getenv('browser')
    In PHP, use getenv():

    (Please see this comment by juliosecco on why you should use getenv() over $_ENV.)
    $browser = getenv('browser'); // Or $browser = $_ENV['browser'];
    In Ruby, use ENV:
    browser = ENV["browser"]
    Saving variables
     
    NOTE: This section is out of date as of Alfred 3.6. Please see the updated version linked at the top of the post.
     
    As amoose136 points out, any variables you set in a running workflow are not saved. They exist as long as the workflow is running and then disappear. Any Workflow Environment Variables will "reset" to their values in the workflow configuration sheet on the next run.

    Generally, this is what you want, but sometimes you want to save a variable's value. For example, you might have an API_KEY Workflow Environment Variable in the configuration sheet. The user can enter their API key for the service in the configuration sheet, but you'd also like to add the ability to set it from within your workflow, e.g. with a setapikey Keyword and corresponding Run Script action.

    WARNING: As of Alfred 3.4.1, Alfred takes several seconds to notice when info.plist has been updated by something other than itself. As a result, relying on altering info.plist programatically can be problematic, as Alfred won't notice the changes for several seconds (5–10 seconds is typical on my machine). If you update a workflow variable in info.plist and run your workflow again immediately, it is unlikely that Alfred will have picked up the change.

    The Workflow Environment Variables are contained in the variables section of info.plist. Consequently, to update them, you need to update info.plist.

    Regardless of which language you're using, you can call the PlistBuddy program to alter Workflow Environment Variables:
    # Set a variable /usr/libexec/PlistBuddy -c "Set :variables:API_KEY \"ABC-XYZ\"" info.plist # Delete a variable (i.e. remove it entirely from Workflow Environment Variables) /usr/libexec/PlistBuddy -c "Delete :variables:API_KEY" info.plist
    In Python, there's no need to use an external program, as it has the built-in plistlib library:
    from plistlib import readPlist, writePlist # Read info.plist into a standard Python dictionary info = readPlist('info.plist') # Set a variable info['variables']['API_KEY'] = 'ABC-XYZ' # Delete a variable del info['variables']['API_KEY'] # Save changes writePlist(info, 'info.plist')
    (Note: plistlib only works with XML property lists, which is fine for info.plist, but using PlistBuddy is generally more robust.)

    Don't forget: any changes you make to info.plist only take effect the next time the workflow is run. This likely doesn't matter in most cases, but if you need a variable to be updated immediately (i.e. also for the current workflow run), you must also set it "live" using one of the methods described in the Setting variables section above.

     
  19. Like
    dfay got a reaction from nm1 in Workflow Picker   
    Just updated this with a new version for Alfred 3.
  20. Like
    dfay got a reaction from davidswanson in A little baffled by Alfred Remote   
    Well another scenario I've discovered through some error and trial is to control a computer with an unresponsive keyboard and mouse.  I managed to get everything locked up and beachballing, ready to power down in desperation, but Alfred Remote was able to Quit All Apps.
  21. Like
    dfay reacted to deanishe in Open app in background   
    Big +1 for this.
     
    Had no idea it was even possible.
     
    Actually, I'm rather astonished by how badly I need this considering I didn't think it possible 60 seconds ago.
  22. Like
    dfay got a reaction from mixterdee in Workflow Picker   
    Just updated this with a new version for Alfred 3.
  23. Like
    dfay reacted to kevnk in Post Notification in the middle of a bash script while loop   
    Awesome! That was helpful. It took me a while to find the "new workflow trigger" you were talking about, but it's Triggers > External and as soon as you create the id, it gives you all the code you need.
     
    Thanks so much!
  24. Like
    dfay got a reaction from Benjamski in snippets as workflow triggers and output   
    I'm thinking still about using Alfred to replace TextExpander.
     
    TE allows snippets to run scripts.
     
    Alfred has snippets....and Alfred workflows can run scripts.  So how about allowing Alfred snippets to be workflow triggers?  
     
    And to go with this -- add a "Type Text" workflow output (with the option of replacing the incoming snippet).
     
    It seems like these would open up a whole lot of automation options, by linking up two existing features, and sticking with the paradigm that folks are used to in building Alfred workflows.
     
    D
  25. Like
    dfay reacted to FroZen_X in Running AppleScript with Alfred to unminimize windows is slow   
    I'm silly....way way way better solution....forget about the delay or anything else....
    Go to your workflow->doubly click on your hotkey to open the hotkey settings(can also right click->configure)->Right click in the hotkey field and change
    the trigger behaviour to "Wait until modifier keys are released"
    That will do it!
     
    Always learn something new ^^
×
×
  • Create New...