Waiting for an Application to launch

I use an AppleScript to implement “Open Terminal Here” functionality on my Macs, and just now I noticed on the Intel machine it had stopped working properly if Terminal wasn’t already running. For some reason, on PPC it still sends the message through, but on x86 it doesn’t. So, I had to use the following code to get it to work if Terminal wasn’t already running, which can be generalised to any application: repeat while "Terminal" is not in name of processes     delay 0.5 end repeat The whole script, which can be saved as an application bundle, set to not show in dock, and then placed in the Toolbar:

 1    -- when the toolbar script icon is clicked
 2    --
 3    on run
 4    	tell application "Finder"
 5    		activate
 6    		try
 7    			set this_folder to (the target of the front window) as alias
 8    			--display dialog POSIX path of this_folder
 9    		on error
10    			set this_folder to startup disk as alias
11    		end try
12    		my process_item(this_folder)
13    	end tell
14    end run
18    -- This handler processes folders dropped onto the toolbar script icon
19    --
20    on open these_items
21    	repeat with i from 1 to the count of these_items
22    		set this_item to item i of these_items
23    		my process_item(this_item)
24    	end repeat
25    end open
28    -- this subroutine processes does the actual work
29    --
30    on process_item(this_item)
31    	tell application "System Events"
32    		try
33    			get process "Terminal"
35    			tell application "Terminal"
36    				activate
37    				do script "cd " & (quoted form of POSIX path of this_item)
38    			end tell
39    		on error -- Terminal Not running, launch and run in first window.
40    			launch application "Terminal"
41    			-- May need to wait until Terminal finishes launching
42    			repeat while "Terminal" is not in name of processes
43    				delay 0.5
44    			end repeat
45    			tell application "Terminal"
46    				activate
47    				-- So we don't create a new window: in window 1
48    				do script "cd " & (quoted form of POSIX path of this_item) in window 1
49    			end tell
50    		end try
51    	end tell
52    end process_item

Installing Missing Sync on a Hackintosh

I am a registered user of Missing Sync for PalmOS, but it wouldn’t install on my Dell running OS X. Easy to fix: copy the installer package somewhere writable, and then open the package, find the file Contents/Resources/InstallationCheck. Edit this file in a text editor (luckily, they made it a bash script!), and before the final line (exit $RETVAL), insert: exit 0 Crude hack, but it gets it installed. Now to reboot and see if it will actually run!

Reinstalling Windows, Again

Here I go, reinstalling WinXP for the umpteenth time this week. I seem to have some corrupted files which prevents me from running all but the most simple of applications. Including IE, and Firefox, btw.

Mounting a share before running an application

I have all of my Music, Movies and TV shows stored digitally on a server, located just below my feet at the moment, but soon to be shifted to another location. This server just runs SMB file sharing, and provides access to the same files, as well as a heap of other data, to all of the machines in my network. It also provides easy access to media and installers for guest users, too. The one thing I like about Windows1 over OS X is that you can have shares set to auto-mount on bootup. I used to use an AppleScript to do this, which was okay, except OS X still disconnects when you sleep. Not that I sleep my machine much, anyway. Then today, I read a great hint on MacOSXHints: Make sure iTunes mounts a networked music library. Basically, instead of running iTunes from the location it is installed in, you create an alias on the music server volume, and run it (via another alias back into the dock) from there. Then, before loading iTunes, it mounts the volume, if it can find it. Otherwise, iTunes will not run. Which is fine by me, since all of my music is on that server!

  1. Mind you, Windows does have some other crappiness in conjunction with this. Lately, I’ve been finding that it won’t always mount all of the shares, even though I chose automatically mount after rebooting, and it sometimes forgets my passwords. Similarly, you cannot connect more than once to a server with different credentials. I mean, seriously?

Pacifist Bug?

I’ve used Pacifist to extract data from MacOS X Installer Packages before, but I just noticed something that might be a bug. It was on my Dell/Hackintosh, and I haven’t had time to try the same thing on the iMac G4, but I will. I was about to update the OS X x86 system to 10.4.9, and after reading Method to Update hackintosh 10.4.8 to 10.4.9 (Intel SSE2/3), I had backed up the files referenced, and was backing up the whole partition to a disk image. I thought I’d extract a couple of the files listed, and see if I could figure out the differences between them. So I extracted a file using Pacifist to the Desktop, ready to examine it. Okay, the file isn’t there. Go into Terminal, and list the Desktop. Poof. Finder is gone. When it reloads, the file is there. What I suspect is happening (and I haven’t tried it again, just yet), is that the file is copied, and the Finder isn’t notified. When something else tries to access the file, the Finder panics, or something. I will try to reproduce this on the same system, and my PPC setup. Until then, here I go to update…

Broken MBR and Partition Map

Ooh, scary stuff this afternoon. I was preparing to back up my OS x86 installation, and make a bootable version on another partition, but at some stage I must have repartitioned the whole hard drive. Which included the 75GB NTFS partition with Windows XP, and a heap of data on it. I originally had thought it was the NTFS-3G (read/write FileSystem driver for Mac), but, alas, it wasn’t. So, I spent the next few hours downloading repairers, trying in vain to undelete, before I happened across one CD ISO that did the trick - restored the partition information from a backup. I then had to repair the windows installation (fix the MBR and something else, FIXMBR and FIXBOOT), and everything is back to normal. Man, I’m feeling a whole lot happier than I did a couple of hours ago…

Fixing Broken Samba Sharing

Well, I had installed OS X on an unsupported machine, and had virtually everything I wanted working. With two exceptions. Finder wasn’t able to connect to any file sharing servers, but I was able to manually create mounts, using: $ mount_smbfs //user:pass@machine/mount /mnt I was also able to do something similar with AFS shares. Which, by the by, are much nicer - they actually allow me to copy icons from my iMac to my Dell. Then, I happened across this forum post: Personal File Sharing & Samba, JaS 10.4.7 Basically, it seems that some of the files from the Hackintosh installation aren’t perfect. So, the following needs to be done:

1    $ cd /usr/sbin
2    $ sudo rm AppleFileServer
3    $ sudo ln -s /System/Library/CoreServices/AppleFileServer.app/Contents/MacOS/AppleFileServer AppleFileServer
4    $ sudo unlink /System/Library/Filesystems/afpfs.fs

I’m not sure about the last one, but I did it anyway. And then I was able to use the Finder “Connect to Server…” tool. And have shortcuts on my desktop to servers.

MacOS X on Intel

Well, after two days of trying, I finally got OS X to install on my Dell Dimension 4600. In the end, it seems my installation DVD was slightly corrupted, enough to fail on trying to install a particular package. Which, it turned out, was the one that stops kernel panics on boot. Kinda handy. The way I got around it was to use Pacifist to unpack the package on the iMac, and copy the files across using my iPod. This was after countless reboots. I wish I’d thought of it earlier. Like yesterday morning. So, now I’m typing this from the lovely place that is OS X. I managed to get Sound working, just by changing the plug location. Only in-built AC97 sound works, but that’s mainly what I’ve been using anyway. I had been using the PCI soundcard for TeamSpeak, but not for actual system sounds. At the worst, I can just build a cable double adaptor and leave it plugged into both locations. Networking required the download of an extension - AppleIntel8255x.kext, and that worked fine too. In the short term, I just plugged in a Firewire cable to the iMac, and used Internet Sharing to build the network. But this is better, and it even picks up the same IP address (and hostname) from my DHCP server. Graphics still isn’t perfect, but I’m only a few minutes away from downloading a potential driver. In fact, it’s just finished now.

Undocumented Komodo Command

I was trying to do something earlier, where instead of creating a Command, I just used a macro that executed a command, but I wasn’t really able to. Then, I happened to record a macro where, instead of having made the command earlier, I ran it while recording. The following JavaScript is the macro:

// Macro recorded on Sat Apr 14 2007 00:30:57 GMT+0930 (CST)
if (komodo.view) { komodo.view.setFocus() };
Run_RunEncodedCommand(window, ’python -u {'operateOnSelection': True}’);

Now, I just need to see if I can use python macros to get the same effect.

Tonight May Have To Last Me All My LifeThe AvalanchesSince I Left You ★½

Komodo Macros

I’ve been working on a few little macros for Komodo. I’m planning to build a more cohesive set as I use the editor more.

Export HTML Tools.

The first is Copy As HTML Snippet. This gets an HTML representation of the current document and it’s syntax styling, and stores this in the Clipboard. There are two related tools: Export As HTML, and Export Selection as HTML. They save either the whole file, or the current selection. They create a new file, rather than store the data in the Clipboard. Each to her own. The code for each: (recursion: uses the macro to get the code of the macro…)

Copy As HTML Snippet.

 1from komodo import components, document  
 2from xpcom.server import UnwrapObject  
 3import re  
 5# Get the current buffer, and an html representation.  
 6buf = UnwrapObject(document.ciBuf)  
 7html = buf.to_html(False,False,None,True,True)  
 8# Remove some debugging code left by the developers.  
 9html = html.replace('onmouseover="show_class(event.target);"','')  
10html = html.replace("'","'")  
11html = re.sub('SCE_P_.*? ','',html)  
13# Put it into the clipboard,  
14ch = components.classes["@mozilla.org/widget/clipboardhelper;1"].getService(components.interfaces.nsIClipboardHelper)  

Export As HTML

1import komodo  

Export Selection As HTML

1import komodo  

You can get a Project (mutliple part packages are broken on export for me at the moment) with all three macros from: HTML Export Tools.

Java Development Tools

This will eventually, I hope, become a more useful set of tools, perhaps being replaced by better interaction with, for example, Komodo’s native debugger. At the moment, debugging requires knowledge of the specific debugging commands. However, I am confident I can use the inbuilt Breakpoint structure to create breakpoints easily, and step through code.

Build & Execute

This macro calls a Command, at the moment, after saving the file.

 1import komodo  
 5    komodo.findPart('command', 'Java Build & Execute', '*').invoke()  
 7    from xpcom import components  
 8    wwatch = components.classes["@mozilla.org/embedcomp/window-watcher;1"].getService(components.interfaces.nsIWindowWatcher)  
 9    prompt = wwatch.getNewPrompter(wwatch.activeWindow)  
10    prompt.alert("Execution Error", "Unable to find 'Java Build & Execute'")  

Java Build & Execute

This is a Command, with the following in the Command: section if test “%F” -nt “%b.class”; then { javac “%F” ; if test “$?” == “0”; then java -classpath . “%b”; fi; } else java -classpath . “%b”; fi This should all be on the same line. In the Start in: box, insert %D

Java Build & Debug

Basically the same as the above, but with java replaced by jdb: if test “%F” -nt “%b.class”; then { javac “%F” ; if test “$?” == “0”; then jdb -classpath . “%b”; fi; } else jdb -classpath . “%b”; fi Start in: must be %D The project containing all of these can be found at Java Tools.

Python Tools

My python tools are a bit simple at this stage - after all, there’s already a fair bit of stuff in there to work with python! I do have a couple of bits that are useful. The Run Command… dialog is okay, but I always forget to save the document before running it, so I have two pairs of tools, one to Save and Run the file, and the other to Save and Run the file interactively. They are basically the same, with the difference of one command line switch, and the name of the command in the macro.

Save and Run Current Script

 1import komodo  
 5    komodo.findPart('command', 'Run Current Python File', '*').invoke()  
 7    from xpcom import components  
 8    wwatch = components.classes["@mozilla.org/embedcomp/window-watcher;1"].getService(components.interfaces.nsIWindowWatcher)  
 9    prompt = wwatch.getNewPrompter(wwatch.activeWindow)  
10    prompt.alert("Execution Error", "Unable to find 'Run Current Python File'")  

I’ve put a nice icon on it, which you can get by right-clicking on the following image, and downloading it.

Run Current Python File

This is a fairly simple one, there’s really only one trick. python -u “%F” And %D in Start in:, as before. The -u tells the interpreter not to buffer input and output.

Save and Run Interactively/Run Current Python File Interactively

Just add the word Interactively in the two places in the macro, and add -i in just before the -u in the command. Simple!

Execute Selection

Another simple one, this is just a python -u command that has the Pass selection as input box checked.

Execute All

A simple macro that selects all before running the above command. I may try to improve it so it re-selects the initial selection after. Maybe. I just used the macro builder to create this one. Cmd-A, then click on the Execute Selection tool. As before, get all of them from Python Tools.

The Closest Thing To CrazyKatie MeluaCall Off The Search ★★★★★