<?xml version="1.0" encoding="UTF-8"?> <rss
version="2.0"
xmlns:content="http://purl.org/rss/1.0/modules/content/"
xmlns:wfw="http://wellformedweb.org/CommentAPI/"
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:atom="http://www.w3.org/2005/Atom"
xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
><channel><title>Chris Haynie &#187; script</title> <atom:link href="http://chrishaynie.com/tag/script/feed/" rel="self" type="application/rss+xml" /><link>http://chrishaynie.com</link> <description>I&#039;ll fix it when its not broken</description> <lastBuildDate>Sun, 29 Jan 2012 18:46:00 +0000</lastBuildDate> <language>en</language> <sy:updatePeriod>hourly</sy:updatePeriod> <sy:updateFrequency>1</sy:updateFrequency> <generator>http://wordpress.org/?v=3.2.1</generator> <item><title>Python Threading</title><link>http://chrishaynie.com/2009/06/python-threading/</link> <comments>http://chrishaynie.com/2009/06/python-threading/#comments</comments> <pubDate>Mon, 29 Jun 2009 21:14:31 +0000</pubDate> <dc:creator>Chris Haynie</dc:creator> <category><![CDATA[code]]></category> <category><![CDATA[python]]></category> <category><![CDATA[script]]></category><guid
isPermaLink="false">http://chrishaynie.com/?p=94</guid> <description><![CDATA[]]></description> <content:encoded><![CDATA[<p>In order to speed up some of my scripts I&#8217;ve implemented threading using python. Some scripts now run in 1/10th the time they used to as a result.  Here I will try to illustrate some of the key points, hopefully it will be useful to anyone.</p><pre lang="python">
#!/usr/bin/python
import sys
import subprocess
from threading import Thread

class MyThread(Thread):
    def __init__(self,server,cmd):
        Thread.__init__(self)
        self.server = server
        self.cmd = cmd
        self.status = -1
    def run(self):
        proc = subprocess.Popen('ssh %s %s' % (self.server,self.cmd),
                       shell=True,
                       stdin=subprocess.PIPE,
                       stdout=subprocess.PIPE,
                       stderr=subprocess.STDOUT,
                       )
        self.stdout, self.stderr = proc.communicate()

servers = ['shell1.example.net','ssh2.mhost.com','examplebox.net']
command = 'uptime'
cmdlist = []
for srv in servers:
    run = MyThread(srv,command)
    cmdlist.append(run)
    run.start()

for c in cmdlist:
    c.join()
    print "### %s:n%s" % (c.server,c.stdout),
print "## Done"
</pre><p>In my example we loop through servers[] and for each server[] we run the specified command on them, in their own thread! 3 servers in the above example, not a big deal, what if you have 20 servers? 40 servers? huge speed improvement.</p><p>The script can be easily extended to say&#8230; read the servers list in from a configuration file, or accept the &#8216;command&#8217; from the command line arguments, (argv[1:]) etc.</p><p>Enjoy.</p> ]]></content:encoded> <wfw:commentRss>http://chrishaynie.com/2009/06/python-threading/feed/</wfw:commentRss> <slash:comments>0</slash:comments> </item> <item><title>Bluetooth Proximity Lock for Macbook</title><link>http://chrishaynie.com/2008/11/bluetooth-proximity-lock-for-macbook/</link> <comments>http://chrishaynie.com/2008/11/bluetooth-proximity-lock-for-macbook/#comments</comments> <pubDate>Wed, 26 Nov 2008 00:34:43 +0000</pubDate> <dc:creator>Chris Haynie</dc:creator> <category><![CDATA[code]]></category> <category><![CDATA[bluetooth]]></category> <category><![CDATA[hack]]></category> <category><![CDATA[mac]]></category> <category><![CDATA[osx]]></category> <category><![CDATA[script]]></category><guid
isPermaLink="false">http://www.chrishaynie.com/?p=26</guid> <description><![CDATA[I wanted to have my macbook automatically lock and unlock based on if I am in the room or not automatically. Best way to do that I figured would be bluetooth, since I always have my phone on me, and &#8230; <a
href="http://chrishaynie.com/2008/11/bluetooth-proximity-lock-for-macbook/">Continue reading <span
class="meta-nav">&#8594;</span></a>]]></description> <content:encoded><![CDATA[<p>I wanted to have my macbook automatically lock and unlock based on if I am in the room or not automatically. Best way to do that I figured would be bluetooth, since I always have my phone on me, and it has bluetooth. From there I proceeded to google.</p><p><a
title="http://web.mac.com/jhollington/technocrat/The_Technocrat/Entries/2007/3/18_Bluetooth_Proximity_Detection_on_OS_X.html" href="http://web.mac.com/jhollington/technocrat/The_Technocrat/Entries/2007/3/18_Bluetooth_Proximity_Detection_on_OS_X.html">http://web.mac.com/jhollington/technocrat/The_Technocrat/Entries/2007/3/18_Bluetooth_Proximity_Detection_on_OS_X.html</a></p><p>Pointed me to</p><p><a
title="http://www.apple.com/downloads/macosx/system_disk_utilities/proximity.html" href="http://www.apple.com/downloads/macosx/system_disk_utilities/proximity.html">http://www.apple.com/downloads/macosx/system_disk_utilities/proximity.html</a></p><p>he also includes a script to automate syncing your phone book and such too</p><p>Another utility in my searching, is called JackSMS</p><p><a
title="http://www.macupdate.com/info.php/id/21860" href="http://www.macupdate.com/info.php/id/21860">http://www.macupdate.com/info.php/id/21860</a></p><p>JackSMS does some cool stuff like, say someone tries to access your laptop while you&#8217;re not there &#8211; the built in isight camera will take their picture and email it then, so I wanted to use JackSMS as well.</p><p>Proximity allows you to set scripts for when you arrive or when you leave, so here are the applescripts I used:</p><p>lock.scpt:</p><pre lang="applescript">﻿tell application "JackSMS" to set lock screen to true</pre><p>unlock.scpt:</p><pre lang="applescript">﻿tell application "JackSMS" to set lock screen to false</pre><p>courtesy of: <a
title="http://www.macosxhints.com/article.php?story=2006061914363693" href="http://www.macosxhints.com/article.php?story=2006061914363693">http://www.macosxhints.com/article.php?story=2006061914363693</a></p><p>update: a better proximity script, copied below, courtesy of:<br
/> <a
title="http://pixelignition.net/better-proximity-applescript" href="http://pixelignition.net/better-proximity-applescript"> http://pixelignition.net/better-proximity-applescript</a><br
/> lock.scpt:<br
/> <a
href="javascript:void(null);" onclick="s_toggleDisplay(document.getElementById('SID719244145'), this, 'Show &#9660;', 'Hide &#9650;');">Show &#9660;</a></p><div
id='SID719244145' style='display:none;'><pre lang="applescript">
global okflag
set okflag to false
set front_app to (path to frontmost application as Unicode text) -- So we can switch back to this after running the fade

-- check if iTunes is running
tell application "System Events"
        if process "iTunes" exists then
                set okflag to true --iTunes is running
        end if
end tell

if okflag is true then
        try
                tell application "iTunes"
                        set currentvolume to the sound volume
                        if (player state is playing) then
                                repeat
                                        --Fade down
                                        repeat with i from currentvolume to 0 by -1 --try by -4 on slower Macs
                                                set the sound volume to i
                                                delay 0.01 -- Adjust this to change fadeout duration (delete this line on slower Macs)
                                        end repeat
                                        pause
                                        --Restore original volume
                                        set the sound volume to currentvolume
                                        exit repeat
                                end repeat
                                set comment of current track to "Proximity Paused"
                        end if
                end tell
                tell application front_app
                        activate
                end tell
        on error
                beep
        end try
end if

tell application "JackSMS" to set jack status to "on"
delay 1
tell application "DeskShade"
        lock
end tell
end run
</pre></div><p>unlock.scpt:<br
/> <a
href="javascript:void(null);" onclick="s_toggleDisplay(document.getElementById('SID1202630469'), this, 'Show &#9660;', 'Hide &#9650;');">Show &#9660;</a></p><div
id='SID1202630469' style='display:none;'><pre lang="applescript">
tell application "ScreenSaverEngine" to quit
tell application "DeskShade"
        unlock
        quit
end tell
tell application "JackSMS"
        quit
end tell

global okflag
set okflag to false
set front_app to (path to frontmost application as Unicode text) -- So we can switch back to this after running the fade

-- check if iTunes is running
tell application "System Events"
        if process "iTunes" exists then
                set okflag to true --iTunes is running
        end if
end tell

if okflag is true then
        try
                tell application "iTunes"
                        set currentvolume to the sound volume
                        if comment of current track is "Proximity Paused" then
                                set comment of current track to ""
                                play
                                repeat with j from 0 to currentvolume by 2 --try by 4 on slower Macs
                                        set the sound volume to j
                                end repeat
                        end if
                end tell
                tell application front_app
                        activate
                end tell
        on error
                beep
        end try
end if
</pre></div> ]]></content:encoded> <wfw:commentRss>http://chrishaynie.com/2008/11/bluetooth-proximity-lock-for-macbook/feed/</wfw:commentRss> <slash:comments>2</slash:comments> </item> </channel> </rss>
<!-- Served from: chrishaynie.com @ 2012-02-06 22:53:28 by W3 Total Cache -->
