Jump to content

MuppetGate

Member
  • Posts

    132
  • Joined

  • Last visited

  • Days Won

    4

Posts posted by MuppetGate

  1. Date Calculator

     

    Hello there!

    I needed a bit of motivation to learn Python and Alfred workflows, so I thought I’d kill two horses with one bullet, so to speak.

    Right, so this is a date calculator – kind of. It won’t tell you when you will the lottery, or how long you’ve got to hide your ‘arty videos’ before your wife gets home, but it will answer one or two very simple questions about dates.

     

    dcalc1.png

    For example, if you enter

     

    dcalc 25.12.14 - 18.01.14

     

    then it will tell you the number of days between those dates. Note that the workflow parses the command as you enter it, so you’ll see invalid commandinvalid expression and invalid formaterrors as you type. Once you’ve completed the command then you’ll be given the result.

    You could also try

     

    dcalc 25.12.14 - now

     

    for the number of days until Christmas. (Always seems so far away . . .)

    Maybe you don’t want it in days, but would rather it in weeks:

     

    dcalc 25.12.14 - now w

     

    or days and weeks

     

    dcalc 25.12.14 - now wd

     

    or years, months, weeks and days

     

    dcalc 25.12.14 - now ymwd

     

    or

     

    dcalc 25.12.14 - now long

     

    will do the same thing. Personally, I always use the long format because it’s more accurate.

    For those who like to look ahead, you can add days to a date

     

    dcalc now + 6d

     

    or weeks

     

    dcalc 18.12.14 + 9w

     

    or combine ‘em

     

    dcalc 18.12.12 + 5y 9d 3w - 2d + 1d 1w

     

    What does that mess do?

    • Take the date 18.12.12 
    • Add 5 years
    • Add another 9 days
    • Add another 3 weeks
    • Then take off 2 days
    • Add another 1 day
    • And then add another 1 week

    If you want to know what week number you’re in, then try this:

     

    dcalc today wn

     

    Or for a specific date:

     

    dcalc 25.12.14 wn

     

    You can also use the today thing in other places too:

     

    dcalc today + 4d

     

    And we have another thing called time because the workflow can handle times too:

     

    dcalc time + 6h 8M

     

    will add 6 hours and 8 minutes to the current time. Note the capital ‘M’ to denote minutes. Odd, I know . . . sorry, but the workflow has to distinguish between this and a small ‘m’ (for months). I figured make this one a capital because it would see much less use. (It has for me.)

    If you just want the current time, then just enter

     

    dcalc time

     

    Here’s another time calculation

     

    dcalc 14:35 + 6h

     

    That’s the time 6 hours from now, and for real nerdiness:

     

    dcalc 21.06.14@14:20 - 23.01.12@09:21 long

     

    Probably not all that useful, but some of this other stuff might be. You know all about

     

    dcalc now

     

    For giving you the current time and date. While you can use 

     

    dcalc tomorrow

     

    for tomorrow’s date, and as you would expect

     

    dcalc tomorrow + 1d

     

    will give you the day after tomorrow.

     

    dcalc next tue

     

    will give you the date next Tuesday. Or for for Thursday you could enter

     

    dcalc next tue + 2d

    if you’re still a little too inebriated to realise that

     

    dcalc next thu

     

    will give you the same answer.

    That about covers it, I think. I haven’t done anything clever with locales, but you can pick a different date format with

     

    dcalcset date format

     

    And we also support both 12-hour and 24-hour time formats. 

     

    dcalcset time format

     

    I would recommend sticking with the 24-hour format; it's a lot easier to type because the AM/PM symbols have to be in upper case.

    You can also set the combined date and time format using:

     

    dcalcset date and time format

     

    If you’re ever puzzled by invalid command or invalid expression errors, then start with the settings; they might be set incorrectly.

    Oh, almost forgot.

     

    dcalc easter

     

    Is the date for next Easter Sunday, for no other reason that I can never remember it, and now there’s an easy way to find out how many days until Christmas:

     

    dcalc today - christmas

     

    And to celebrate finishing my new book, I decided to add:

    dcalc passover

     

    Alternative parser

    If surround a simple expression in double quotes, then something quite magical happens:

     

    dcalc "4 hours 8 minutes after 4pm"

     

    or

     

    dcalc "6 weeks and 4 days after next wednesday"

     

    or

     

    dcalc "1 day after tomorrow"

     

    Yup! A natural date language parser! 

    You can even combine it with the existing parser:

     

    dcalc "next friday" + 1d

     

    This is a little bit experimental (I might drop it later if it proves to be problematic), but I thought I'd throw it in for a bit of a fun.

     

     

    Credits

    A list of things that made my first attempt at Python programming possible:

    • Dean Jackson for his more-than-slightly awesome Alfred Workflow framework(Jetbrains(HumanFriendly(Python-DateUtil(PyPEG(ParseDateTime(Programming Praxis(MIT(http://opensource.org/licenses/MIT) one will do. :-)

      The MIT License (MIT)

      Copyright © 2014 MuppetGate Media

      Permission is hereby granted, free of charge, to any person obtaining a copy

      of this software and associated documentation files (the "Software"), to deal

      in the Software without restriction, including without limitation the rights

      to use, copy, modify, merge, publish, distribute, sublicense, and/or sell

      copies of the Software, and to permit persons to whom the Software is

      furnished to do so, subject to the following conditions:

      The above copyright notice and this permission notice shall be included in

      all copies or substantial portions of the Software.

      THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR

      IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,

      FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE

      AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER

      LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,

      OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

  2.  

    I just looked through the programming guide for LaunchBar 6 "actions" which are their equivalent of workflows. Alfred, in general, has more comprehensive workflow support (not even counting the GUI layout tool), but LaunchBar 6 has some features it would be nice to see in Alfred:

     

    - Scripts can be marked to be killed if they don't return before the next keypress, e.g., user types 'A', script searches the internet, user types 'B', script is killed and re-run with 'AB'
     
      This is an overall feature that's been requested many times but I don't think anyone actually mentioned killing the currently running script.
     
    - Scripts support either 'strings' or 'paths'
     
      I believe a script that takes a path gets path completion support in the LaunchBar entry box.
     
    - Scripts can return a 'string', a 'path' or a complex result
     
      LaunchBar assumes defaults for everything if your script just returns a string or a path instead of XML, JSON, etc.
     
    - Environment variables are passed to the script w/various paths and information about the state of the option key, command key, etc.
     
    - LaunchBar can accept script output in JSON, XML or a property list XML
     
      I don't care about property list XML, but I would love if JSON was an option.
     
    - Items returned by a script can include a quicklook URL
     
    - Items can indicate another script to run to get the next 'level' of items, e.g., a multi-level menu
    - Items can directly list out the next 'level' of items
     
      Various Alfred scripts now have hacks that "re-call" the script and mimic multiple levels of results. LaunchBar bakes it into the workflow model.
     
    - LaunchBar actions are code signed
     
    - LaunchBar supports using JavaScriptCore as a scripting language
     
    - Scripts can marked to be initiated by LaunchBar but LaunchBar immediately returns (doesn't wait for output)
     

     

     

    Agree with just about everything here, especially the ability to get data from other scripts & workflows to get multi-level items. I'm playing with workflows at the moment and the Alfred-way is pretty hard going.

     

    Since Apple is including Javascript for Automation in Yosemite then I guess Javascripting will land in the Autumn. This won't help folk who don't upgrade to the new OS though.

     

    I notice that Launchbar also has the beginnings of a site for sharing extensions. I think Alfred is also lacking a standardised way to do this. Packal is great, but we still can't download and update workflows from inside Alfred.

     

    One other small thing:

     

    I'd like access to the side window that Alfred uses to display contact information, song details etc.  The Notification Centre window is sometimes too small, and sending messages through Large Type can look like your shouting at people.

  3. +1

     

    Especially the part about using Applescript dialogs and the flashing.

     

    This would replace the need for two items I asked for a couple of years ago:

     

    1. An input workflow module that could be used to pick up extra bits of info from the user.
    2. A conditional workflow module that could branch other modules depending on the value of its output. 

    Something like this would also bring in a lot more workflows that wouldn't need to interact directly with users. We could have workflows that just store settings, for example.

  4. Hi there.

     

    I'm playing around with Ruby workflows and I'm trying to pass a keyword parameter out to a notification.

     

    The problem seems to be that I'm not reading the input parameter passed in on the workflow invocation.

     

    The workflow script just does this:

     

    print ARGV

     

    And all I'm getting is an empty array.

     

    Is there something I've missed?

  5. Great articles. Thanks for taking the time to write these.

    Why are you pasting the code into the Script boxes instead of using external scripts?

    For the same reason 'Hello World' examples aren't written using IDEs, closures and recursion:

    Keeping it as simple means the user can get something up and running quickly, which encourages him to press on with something more complicated.

    It keeps the focus on Alfred, not on introducing extras like RubyMine or PyCharm or other tools which are distracting for the learner.

  6. I think that the entire purpose of Alfred's results is exactly this ... to display results. Wouldn't creating 'another' display window defeat the purpose of Alfred?

    Came across this thread while looking for HUD techniques for Alfred.

    The thing is, Alfred already has another display window: the notifications area.

    So I don't think it's unreasonable to have a HUD display for showing help pages or messages that need more space.

    However, the HUD should only allow for one action: close.

    It would be great if there was a built-in workflow module that supported this.

    Though I can see how allowing the HUD to render as HTML could cause problems.

  7. My dream is that there would be a new type of "Workflow Input" called "Variable" or "Setting".  You could give it a name and then there would be a simple text box to let a novice user type in a value for the variable/setting.  I could then connect these input variables to my more complicated/generic scripts and have those scripts use the user-defined variables.  I imagine these would be available to my scripts the same way that the "{query}" variable can be used.

     

     

     

    Thanks for considering.

     

    Yup, I think this one has been suggested a couple of times. 

     

    Good idea.

     

    I think integrating this into Alfred would make the whole process a lot more integrated. As a prompt is run then Alfred could shift his window contents off to the left, which would be a visual cue that you are still running the same workflow.

     

    Aesthetically it would be much nicer.

  8. Alternatively, I would suggest looking at your workflow and see how you can create filters to narrow down things. A lot of people think it's better to just add lower level folders to the scope so that Alfred searches everything but it affects performance and just clutters your results to the point that you have so much in your search results that you can't find what you were actually looking for.

     

    I personally don't want EVERY type of file/folder in my search results because I typically know what I'm looking for. I know if I'm looking for a picture, or a folder, or if I want to look in a specific folder that I work in frequently. I use workflows and filters to drastically reduce results to match exactly what I want.  For instance, my defaults are to only show contacts, preferences and applications in results. I have filters for searching for ONLY folders, bookmarks, mail, chat, etc because I know when I'm looking for those things. 

     

    The problem is that this isn't necessarily related to just workflows; the search results in general can be overly broad. If I type 'fav' then I'd rather not have every fav.ico file show up in the search. I'd like some way to exclude '*.ico' or 'fav.*' from the default results.

     

    I think this is one of the tradeoffs with using Spotlight. Most of the work (updating, indexing etc.) is handled for you, but the cost is flexibility. I know applications similar to Alfred don't share its shortcomings (difficult to control inclusions/exclusions; doesn't deal with networked drives) because they build and maintain their own indexes. On the other hand, these other apps don't look anywhere near as good, and can be a pig to set up  :mellow:

×
×
  • Create New...