Tag Archives: AppleScript

Moving Application Windows in OS X via Apple Script

Those of you lucky enough to have multiple monitors hooked up to you MacBook or MacBook Pro when you work may have come across this issue. When you remove that extra monitor some applications don’t get re-positioned back on to your laptop display. I had this with one particular application that I use frequently, KeePassX. Well somewhere along the way I dug up this use full terminal/apple script that solves the issue.

property processesToIgnore : {}
tell application "Finder"
	set _b to bounds of window of desktop
	set screen_width to item 3 of _b
	set screen_height to item 4 of _b
end tell
tell application "System Events"
	set allProcesses to application processes
	set _results to ""
	repeat with i from 1 to count allProcesses
		set doIt to 1
		repeat with z from 1 to count processesToIgnore
			if process i = process (item z of processesToIgnore) then
				set doIt to 0
			end if
		end repeat
		if doIt = 1 then
			tell process i
				repeat with x from 1 to (count windows)
					set winPos to position of window x
					set _x to item 1 of winPos
					set _y to item 2 of winPos
					if (_x < 0 or _y < 0 or _x > screen_width or _y > screen_height) then
						set position of window x to {0, 22}
					end if
				end repeat
			end tell
		end if
	end repeat
end tell

I don’t recall where I may have dug this up, but if you think you know, please let me know in the comments so I can give credit.

AppleScript Fix for Error 51: Unable to communicate with the VPN subsystem on Cisco 3000 VPN Client

Over at Ian Talks Tech my friend Macca recently posted a fix for the “Error 51 : Unable to communicate with the VPN subsystem” error from a cisco vpn client. I had also encountered the same problem some time ago and it brought my own memories rushing back. I had initially discovered a fix for the error 51 problem over at a different site, Anders.com . Since finding the one line terminal command answer to the issue that my cisco 3000 client had thrown up I thought no more of it. Ian’s post jogged my memory about my own search and I immediately put my copy and paste skills to good use to come up with an apple script that you can run to fix this cisco vpn client error.

All you need to do is open the apple script editor.

“/Applications/AppleScript/Script Editor.app”

Then paste a similar line of code to the commands that Macca and Anders mentioned:

do shell script "ifconfig fw0 down" with administrator privileges
do shell script "ifconfig fw0 up" with administrator privileges and password
do shell script "/System/Library/StartupItems/CiscoVPN/CiscoVPN  restart" with administrator privileges and password

Feel free to run the apple script to test it, just note you will be asked for an administrator password for the script to run.

Once you are happy you should compile and save the script to keep it safe, or “save as” and choose application. Alternatively, you could just download the AppleScript Fix for the “Error 51: Unable to communicate with the VPN subsystem” problem, that I have pre compiled as an application.

Credit where its due.
Ian Talks Tech for jogging the grey matter.
Anders.com for solving my problems when I had them.
Apple for showing me how to do shell scripts in Apple Script.