frillo Posted October 14, 2016 Posted October 14, 2016 Hello everyone, I'm new to Alfred, purchased few weeks ago and now I'm fiddling with it, using very few features. I guess I'll discover more and more from now on. One question: every day, for a newsletter, I have to paste a string like /content/xxx/eveningnews/2016/603/web/popover/ban_whatever At the moment, I'm using a snippet with a generic string, but the thing is that every day the number after the year increases by one (instead of /603/ should be /604/). Is this something the can be automated in Alfred? Where should I start? Maybe scripting? Thank you, sorry for my english, I'm from Rome, Italy…
vitor Posted October 14, 2016 Posted October 14, 2016 (edited) Yes, it is possible, and yes it requires some scripting, but should be fairly simple. But what about the /2016/ part? Will that change when we enter 2017? And if so, does the other number keep increasing at the same rate as usual? Today, Friday, October 14, 2016, what is the number? Edited October 14, 2016 by vitor
frillo Posted October 14, 2016 Author Posted October 14, 2016 I don't really care about the year, after all, you should change it once in a year time… Today's string is the one I've posted: /content/xxx/eveningnews/2016/603/web/popover/ban_whatever So, you're suggesting to do it via a workflow, implying a little script. Can't GREP come in handy? Thank you for the quick reply, Guido
vitor Posted October 14, 2016 Posted October 14, 2016 (edited) Including the year takes no more effort than doing the rest, so no reason not to include it as well. grep has no relation to the task, all you need is simple date calculation. First I checked when 603 ago was (2015/02/19). Then, having that as the baseline, we need only check how many days have passed since then at the time we run the script. Using ruby: require 'Date' initial_date = Date.new(2015, 02, 19) today = Date.today current_year = today.year day_difference = (today - initial_date).to_i print "/content/xxx/eveningnews/#{current_year}/#{day_difference}/web/popover/ban_whatever" Here is a workflow you can download that does this for you. You can either use the Keyword (by default dd) or set a Hotkey. After you run it, the result will both be copied to your clipboard and pasted to your frontmost app. If you need to change the exact text that is output, go into the Run Script node (right at the middle of the workflow), and change the text in quotes on the last line. Just make sure #{current_year} and #{day_difference} stay intact as the places where substitutions will occur. Edited October 14, 2016 by vitor
frillo Posted October 14, 2016 Author Posted October 14, 2016 Hey Vitor, thank you a ton! Didn't mean to make you work in my place… but you're definitely more than welcome ;-) I owe u 1… g
vitor Posted October 14, 2016 Posted October 14, 2016 Glad to help. It was a simple enough workflow to make. Naturally, if you’d like details on how exactly it works, feel free to ask, though this one should be simple to understand.
deanishe Posted October 15, 2016 Posted October 15, 2016 22 hours ago, frillo said: I don't really care about the year, after all, you should change it once in a year time… I always say that. And every year in the middle of March, I'm still finding scripts that aren't working properly because I hardcoded the year… frillo 1
frillo Posted October 15, 2016 Author Posted October 15, 2016 If I can… There is something left to adjust. The number should increment ONLY on working days, NOT on Saturdays and Sundays… maybe I'd need an if…then cycle before the actual day_difference routine?
deanishe Posted October 15, 2016 Posted October 15, 2016 13 minutes ago, frillo said: If I can… There is something left to adjust. The number should increment ONLY on working days, NOT on Saturdays and Sundays… maybe I'd need an if…then cycle before the actual day_difference routine? When you say "working days", does that also exclude public holidays? In that case, you'd probably want to store the counter in a workflow variable. Perhaps add a second variable that stores the current date. That way you can test if the script has already been run today, and not increment the counter again if it has.
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