Showing posts with label mac. Show all posts
Showing posts with label mac. Show all posts

Wednesday, May 5, 2010

Getting EyeTV to Put Your Mac to Sleep ... Intelligently!

One feature that I _really_ miss in EyeTV is the ability to put my Mac to sleep after a recording. It is possible to write an AppleScript that reacts to the RecordingDone signal in EyeTV, but my previous foray into that area ended up with a simple script that said something like
on RecordingDone(recordingID)
tell application "Finder" to sleep
end RecordingDone
This works to some extent but it does have some serious flaws. First and foremost it ruins your second recording if you have scheduled to record two programs back-to-back. In that case EyeTV records the first program, emits the RecordingDone signal, starts recording the second program, and about five seconds into that recording the computer goes to sleep ;-) Another problem with this approach is when you are recording something while you are working on the computer - in that case your computer suddenly goes to sleep while you are working.

This has annoyed me quite a bit, but seemingly not enough for me to actively search for a better solution - until today. Googling around a bit I found this script: http://forums.elgato.com/viewtopic.php?f=91&t=1045#p18834. I have altered it a tiny bit to change the timeouts and to put the computer to sleep instead of powering it off. The result is here:
on RecordingDone(recordingID)
set isCurrentlyRecording to check_eyetv_is_recording()
if isCurrentlyRecording is false then
with timeout of 300 seconds
tell me to activate
display dialog "Warning: EyeTV has now finished recording and the system will automatically shut down in 5 minutes unless you click Stop!" with icon 2 buttons {"Stop!"} giving up after 300 default button "Stop!"
set theresults to the result
if gave up of theresults is true then
tell application "System Events" to sleep
end if
end timeout
else
quit
end if
end RecordingDone

to check_eyetv_is_recording()
delay 30
tell application "EyeTV"
if is_recording then
return true
else
return false
end if
end tell
end check_eyetv_is_recording
This script works perfectly! When the recording is done a dialog is displayed telling you that the computer will be put to sleep in five minutes, and if you press the stop button you can keep the computer awake.

Update: A guy called Michael asked we where to put the script to make it work. You are supposed to save the scripts as /Library/Application Support/EyeTV/Scripts/TriggeredScripts/RecordingDone.scpt

Thursday, March 11, 2010

Playing around with MacJournal

I have recently bought the MacHeist nanoBundle2 which included a license for MacJournal - yet another journaling software for Mac. I already have Evernote, which seems to be far better than MacJournal for journalling, but MacJournal has some blogging features that I may be interested in. So I guess I’ll give it a try. This entry is written in MacJournal b.t.w. ;-)

This image was just copied into the editor window - and then resized a bit to try that out as well. It’s a photo I took during my recent vacation in Sweden b.t.w.


Now lets try some pre-formatted text (I need that for displaying code examples). I did this by changing the font in MacJournal to Courier 12pt - I would have liked to edit HTML tags instead...:

def compare_us(x, y):
return true if x == y else false

And then some regular text again...

Edit: Well, that did not work at all! I guess MacJournal is not for me then :-) My initial experiences with the software have not been very good. The first time I added a blog the application crashed, and I had to try five times before the auto update function actually worked. When adding a blog entry it did not append any of the tags I chose, the editor did not allow me to edit the HTML source etc. Conclusion: it is a crappy blog editor.

Tuesday, February 9, 2010

XeLaTeX on a Mac

As I wrote a couple of hours ago, I am currently writing my thesis using XeLaTeX. In the process I have found that the MacPorts version of XeLaTeX seems to be broken when it comes to accepting/finding user-installed fonts. My LaTeX template needs a font called Fontin Sans that I have downloaded and installed into my "Font Book" on my Mac. After doing that the MacPorts version of XeLaTeX still couldn't find the font, so I uninstalled the texlive packages fro MacPorts and installed the MacTeX 2009 package instead. And now everything works :-)

Friday, September 18, 2009

Native Mac PyGTK for Snow Leopard

I have just made a fresh build of native PyGTK for Mac on my new Snow Leopard install. It seems to be working - I have only tested my simple hello_pygtk.py script, and that works at least ;-)

You can grab the new build here: MacPyGTK_SnowLeopard_091809.dmg

Remember to follow the three simple instructions in README.txt in order to make it work. B.t.w., one has to be running Python in 32-bit mode for it to work. This can be done in two ways:
  1. By setting this environment variable VERSIONER_PYTHON_PREFER_32_BIT=yes
  2. By issuing this command (once): defaults write com.apple.versioner.python Prefer-32-Bit -bool yes
I would prefer setting the environment variable in a script starting my PyGTK application. That way I am changing as little as possible in the standard setup of the machine...

Thursday, September 17, 2009

Piping output of shell commands into the clipboard

I love my terminal! The availability of a proper shell and set of *nix tools is one of the main reasons that I dared switch to Mac OS X two years ago. I have been used to having the full GNU tool chain on the Linux systems I have been using the last 10 years, and there is no way I will ever give that up :-)

Today I learned something new about my terminal on OS X; I learned about the pbcopy and pbpaste commands. These two shell commands copy shell output into the clipboard, and pastes the clipboard content into the shell, respectively. I.e., today I needed to grep+cut through some large log files, and the results of these commands I wanted to paste to a spreadsheet. Instead of having to 1) perform the command, and then 2) use the mouse to scroll up and select all of the results to copy-paste them into the spreadsheet, I found that I could use pbcopy to pipe stdout directly to the clipboard:
grep foo logfile.txt | cut -d " " -f1,2,4 | pbcopy
After running this I could just go to my spreadsheet application and insert the three selected rows.

This little command is a real time saver I can tell you! I must have saved at least an hours work today alone ;-)

Wednesday, July 15, 2009

Making your OS X hostname stick

If you are both a Mac user and a terminal junkie, as I am, you will probably have noticed that your computers hostname changes whenever you enter a new network environment[1]. More precisely, when you join a network through a DHCP server in some cases it also assigns you a new hostname. This has been a major annoyance to me for some time now, so I finally decided to find out how to make my hostname stick. And, as it turns out, that is of course quite simple to do:

1) Issue the command "sudo vi /etc/hostconfig"
2) Add the line HOSTNAME=my-hostname to this file (pressing i to enter edit mode).
3) Save and close (that's Esc to quit editing mode, and then :wq + Enter for you vi rookies)

The HOSTNAME line may already exist on your system in which case its value will be "-AUTOMATIC-". In that case you just replace that with your hostname. It was not there on my Leopard (client) machine.

Oh yeah, thanks to Robert Brewer for teaching me how to do this. Take a look at his article if you are interested in getting some more detailed information about the whole hostname determination business on OS X.

[1]: For those of you not used to using a terminal a new command-line in a terminal typically starts with "username@hostname:top-level-path$". E.g., my prompt right now shows "madsk@leela:Development$".

Tuesday, May 19, 2009

Controlling the firewall on Mac OS X 10.4 (Tiger) from the command line

I have just had the need to control (actually disable) the firewall on a Mac running OS X 10.4 (Tiger). This should be no problem; just start System Preferences go to Sharing... The problem was that the only connection I had to the machine was through SSH, so going to System Preferences was not an option.

Luckily the firewall can be controlled with the ipfw command on the command line. Take a look at this article at macdevcenter for an example of how to use ipfw.

And, to disable the firewall all that is needed is thus:
sudo ipfw disable firewall

Update: To disable the firewall on Mac OS X 10.5 (Leopard) you can issue the following command:
sudo defaults write /Library/Preferences/com.apple.alf globalstate -int 0