gandalfsaxe Posted December 10, 2014 Share Posted December 10, 2014 (edited) Hello, I'm working on a workflow to reduce distractions for a set amount of time. I've been trying to extend this very simple script: http://johnback.us/blog/2013/07/02/instantly-remove-all-distractions-with-applescript/ The purpose of above script is to simply close specified applications and run the application SelfControl for 60 minutes. The first problem: To generalize this to any amount of minutes allowed by SelfControl, I have in Alfred created a keyword with required argument separated by space and having it run the action "Run NSAppleScript", simply substituting 60 by q: tell application "System Events" tell process "SelfControl" tell slider of window "SelfControl" to set value to q click button "Start" of window "SelfControl" end tell end tell This seemingly does not work. I have tried twice with two different numbers (I think 15 and 60) and the first time, it went off at 1h 30min, the second time at 1h. EDIT: It seems like the original script does not even work actually. As mentioned in two comments on the blog post, the script will tell SelfControl to start, but will not correctly set any new value; just use the last used value. So the question actually becomes, is this slider even possible to set in AppleScript? The second problem: Furthermore I want to have the script close specified programs (specifically the chat application Telegram) and open them again after the set time. This is where I run into trouble. I've tried this: tell application "Telegram" quit end tell delay q tell application "Telegram" to run And this works perfectly. The problem then is that the "SelfControl" application uses minutes and the "delay" command uses seconds as a time unit. I have naïvely tried to fix this by running "delay 60*q" but this doesn't work - the application never opens again. Any suggestions? Edited December 10, 2014 by Fnantier Link to comment
spikespikespike Posted April 3, 2015 Share Posted April 3, 2015 Hey, SelfControl requires you to type in your password to start the blocking. Your script does not reference the user's password at all. I suspect that might be the problem. There was an additional forums post about SelfControl from February 15 that you can find here: http://www.alfredforum.com/topic/5496-distraction-free-freedomapp-workflow/?hl=selfcontrol. His script does reference entering your password. Hope this helps Link to comment
deanishe Posted April 18, 2015 Share Posted April 18, 2015 (edited) The second problem: Furthermore I want to have the script close specified programs (specifically the chat application Telegram) and open them again after the set time. This is where I run into trouble. I've tried this: tell application "Telegram" quit end tell delay q tell application "Telegram" to run And this works perfectly. The problem then is that the "SelfControl" application uses minutes and the "delay" command uses seconds as a time unit. I have naïvely tried to fix this by running "delay 60*q" but this doesn't work - the application never opens again. Any suggestions? To do multiplication, you first have to turn q, which is a string, into a number: set delayMinutes to q as integer set delaySeconds to delayMinutes * 60 How are you running that AppleScript exactly? delay q blocks the script, so if you run that as a Run NSAppleScript Action, you can block Alfred. Anything that takes more than a fraction of a second to run should go in a normal Run Script action with Language /usr/bin/osascript. Edited April 18, 2015 by deanishe Link to comment
gandalfsaxe Posted August 22, 2015 Author Share Posted August 22, 2015 Hi, Sorry for the late reply. The solution I ended up with involved just making a keyboard shortcut for toggling "Do Not Disturb" and thus turn off system notifications form chat programs. Sometimes I close the chat programs (Goofy, Telegram) instead to keep mail notifications if I'm having an important conversation. Seems like a fine solution, I don't need "Self-Control" anymore Link to comment
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