alex.agat Posted April 22, 2013 Posted April 22, 2013 Hi all, Just downloaded Alfred! I want to create the following / know if its possible. 1. Type Alfred shortcut 2. Type 'datetime' as a shortcut 3. The workflow automatically calculates the current datetime (hopefully something I can control the formatting of on the backend) and displays it in the alfred hover window. 4. I have the option of going full screen (if this step though has to happen automatically it would be fine) Any help is appreciated!! Thanks Alex
alex.agat Posted April 22, 2013 Author Posted April 22, 2013 Playing around, even getting it to show in a notification would be acceptable (but not ideal). So far I have: on alfred_script(q) return "" + (current date) + "" end alfred_script with a notification displaying the result, but it's blank.
alex.agat Posted April 22, 2013 Author Posted April 22, 2013 Got it for posting to a notification - now its just displaying full screen using command+L -- set today to current date set dateAsString to "" as string set wd to (weekday of today) as string set m to (month of today) as string set dm to (day of today) as string set dm_int to (day of today) as integer set dm_suffix to "" as string set y to (year of today) as string if (dm_int = 1) or (dm_int = 21) or (dm_int = 31) then set dm_suffix to "st" else if (dm_int = 2) or (dm_int = 22) then set dm_suffix to "nd" else if (dm_int = 3) or (dm_int = 23) then set dm_suffix to "rd" else set dm_suffix to "th" end if set dateAsString to dateAsString & wd set dateAsString to dateAsString & " " set dateAsString to dateAsString & m set dateAsString to dateAsString & " " set dateAsString to dateAsString & dm set dateAsString to dateAsString & dm_suffix set dateAsString to dateAsString & ", " set dateAsString to dateAsString & y return dateAsString
jdfwarrior Posted April 23, 2013 Posted April 23, 2013 Got it for posting to a notification - now its just displaying full screen using command+L -- set today to current date set dateAsString to "" as string set wd to (weekday of today) as string set m to (month of today) as string set dm to (day of today) as string set dm_int to (day of today) as integer set dm_suffix to "" as string set y to (year of today) as string if (dm_int = 1) or (dm_int = 21) or (dm_int = 31) then set dm_suffix to "st" else if (dm_int = 2) or (dm_int = 22) then set dm_suffix to "nd" else if (dm_int = 3) or (dm_int = 23) then set dm_suffix to "rd" else set dm_suffix to "th" end if set dateAsString to dateAsString & wd set dateAsString to dateAsString & " " set dateAsString to dateAsString & m set dateAsString to dateAsString & " " set dateAsString to dateAsString & dm set dateAsString to dateAsString & dm_suffix set dateAsString to dateAsString & ", " set dateAsString to dateAsString & y return dateAsString Add a Large Type item to the end of the workflow instead of the Post Notification item. That should do what you are looking for
adayzdone Posted April 23, 2013 Posted April 23, 2013 Hi Alex, You can simplify your script. return date string of (current date)
Carlos-Sz Posted April 23, 2013 Posted April 23, 2013 One of these days I was browsing in full screen and I needed something like that. I thought Alfred already had something like that but I forgot about it. I think you should make a workflow and share with us.
alex.agat Posted April 23, 2013 Author Posted April 23, 2013 One of these days I was browsing in full screen and I needed something like that. I thought Alfred already had something like that but I forgot about it. I think you should make a workflow and share with us. Done: http://www.alfredforum.com/topic/2168-show-date-and-time-in-large-type/
Carlos-Sz Posted April 23, 2013 Posted April 23, 2013 Done: http://www.alfredforum.com/topic/2168-show-date-and-time-in-large-type/ Great!
adayzdone Posted April 24, 2013 Posted April 24, 2013 Nice one. Feature request: Allow an optional +N or -N days. Today is Wednesday, April 24, 2013 date +3 = Wednesday, April 27, 2013
Tyler Eich Posted April 28, 2013 Posted April 28, 2013 Nice one. Feature request: Allow an optional +N or -N days. Today is Wednesday, April 24, 2013 date +3 = Wednesday, April 27, 2013 I use Date Calculator by iEnno; it supports adding/subtracting units of time (days, hours, minutes, months, etc.). I hooked the script up to a 'Large Type' output. Here's a download with my edits
jdfwarrior Posted April 28, 2013 Posted April 28, 2013 Will work on tonight and post I use Date Calculator by iEnno; it supports adding/subtracting units of time (days, hours, minutes, months, etc.). I hooked the script up to a 'Large Type' output. Here's a download with my edits Not sure about other scripting languages but thought I would mention to Tyler since I know he's a PHP nerd like me but, PHP makes doing things like this extremely easy. The PHP function strtotime() will allow you to say current date +/- <some string> and it will return a timestamp to that date/time which could obviously then be converted to a date/time using the date command in PHP. Also, worth noting that, when your dealing with date/time in PHP, it's going to bark at you for not setting the timezone. You could always set a default but then it doesn't work correctly when you distribute to people in other timezones so to fix that, use the PHP exec command to do systemsetup -gettimezone to get back a string of the current machines timezone like this: Time Zone: America/Chicago You could then parse that to grab everything after the Time Zone: and set that string to the new timezone using date_default_timezone_set() Sorry, I got way down a rabbit hole on that one and probably gave a lot more info than anyone cared about.
Tyler Eich Posted April 28, 2013 Posted April 28, 2013 Not sure about other scripting languages but thought I would mention to Tyler since I know he's a PHP nerd like me but, PHP makes doing things like this extremely easy. The PHP function strtotime() will allow you to say current date +/- <some string> and it will return a timestamp to that date/time which could obviously then be converted to a date/time using the date command in PHP. Also, worth noting that, when your dealing with date/time in PHP, it's going to bark at you for not setting the timezone. You could always set a default but then it doesn't work correctly when you distribute to people in other timezones so to fix that, use the PHP exec command to do systemsetup -gettimezone to get back a string of the current machines timezone like this: Time Zone: America/Chicago You could then parse that to grab everything after the Time Zone: and set that string to the new timezone using date_default_timezone_set() Sorry, I got way down a rabbit hole on that one and probably gave a lot more info than anyone cared about. I had never seen strtotime() before (looks awesome); thanks for that It should be noted, though, that every time I tried to use the systemsetup -gettimezone command (both from bash and php exec()), I was denied because my user account does not have administrator access . I know I could use sudo, but I don't want to type Administrator creds just to know the date.
adayzdone Posted April 28, 2013 Posted April 28, 2013 I use Date Calculator by iEnno; it supports adding/subtracting units of time (days, hours, minutes, months, etc.). I hooked the script up to a 'Large Type' output. Here's a download with my edits Thanks Tyler. I thought the addition might be a cool feature for the OP to incorporate in his first workflow. In AppleScript you can use: set newDate to (current date) + 1 * days
alex.agat Posted April 28, 2013 Author Posted April 28, 2013 (edited) Even though I am certainly more comfortable in PHP, since I started my original script in AppleScript I thought why not continue down that path. I have updated my original script to include the +num and -num functionality requested above. Here ya go: http://cl.ly/3w0O0p3Q3j0X Edited April 28, 2013 by alex.agat
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now