Lyle Vogtmann

Tuesday, January 18, 2011

 

How to redirect a running process output to a file and log out

I can't remember how I found this now, but I at least emailed it to myself to remind me about it later. I usually keep tmux or screen running on all my systems, but I do occasionally forget to re-attach, and end up running something (compilation, download, indexing, etc...) that will take a while to complete. Note that I already know about nohup, this tip is in regards to those situations I realize I must close my shell before a long running command completes but has already been started.


ctrl-z
bg

touch /tmp/stdout
touch /tmp/stderr
gdb -p $!

# In GDB
p dup2(open("/tmp/stdout", 1), 1)
p dup2(open("/tmp/stderr", 1), 2)
detach
quit

# Back in shell
disown
logout

Monday, December 06, 2010

 

AppleScript and cron to appease the neighbors.

I should really use this blog more often, share some of these tidbits of info I find useful and invariably forget...

I tend to work at my computer at odd hours, much to the chagrin of my upstairs neighbor. So at night, I switch to using a headset. Since I do this every night now, and it's the same "Open System Preferences -> Sound -> Output -> Headphones -> Close System Preferences" every time, I figure it's a good candidate for automation. The only scripting tool I know of that can operate the System Preferences application (besides manually editing plist files) is AppleScript. So I put together the following script with help from a little googling:

tell application "System Preferences" to activate
tell application "System Events"
    get properties
    tell process "System Preferences"
        click menu item "Sound" of menu "View" of menu bar 1
        delay 2
        set theRows to every row of table 1 of scroll area 1 of ¬
            tab group 1 of window "sound"
        set theOutputs to {} as list
        repeat with aRow in theRows
            if (value of text field 1 of aRow as text) ¬
                is equal to "Sennheiser USB Headset" then
                set selected of aRow to true
                exit repeat
            end if
        end repeat
    end tell
end tell
tell application "System Preferences" to quit


Saved that to my Documents folder as 'Switch2USBHeadset.scpt', and then set up the following cron job to run it automatically at 10pm daily. (Note the use of the 'osascript' command, AppleScripts aren't executable by themselves like bash/python/perl scripts.)

0 22 * * * osascript /Users/vmann/Documents/Switch2USBHeadset.scpt

The only thing I don't like about this so far is System Preferences gets input focus while the script is running, so if I happen to be typing something at 22:00 I might lose a few characters while System Preferences takes over. If anyone knows how to 'activate' an application but avoid stealing focus from any other applications currently running, please let me know!

Tuesday, June 22, 2010

 

Another shot at blogging thanks to Google CL

I can't count how many blogs I've started and eventually abandoned. Even before the 'net, I've had more composition notebooks than anyone would ever need, with only a few pages used in each. I like the idea of writing, more than actually writing anything of note, especially not to share with strangers. But here I am again...

I've tried Blogger/Blogspot before, and many other free and self-hosted blogs. I've also done the manual HTML static pages, and tried my hand at coding a few custom blogging applications. In other words, I've found several ways to procrastinate.

One of the key features I've always wanted in a blog is ease of use. Otherwise I know I won't use it, and end up with another abandoned notebook and wasted time. Google's new command line tool looks very interesting in that aspect.
 

Patrick's farewell doodle

Anybody care to translate it for me?






Archives

June 2010   December 2010   January 2011  

This page is powered by Blogger. Isn't yours?

Subscribe to Posts [Atom]