Learning shell scripting while trying to fix Snow Leopard local network issue :)

Mac OS X is a great system, but this doesn’t mean it’s perfect and without issues. One thing is not working as it would (in Snow Leopard 10.6.X), it’s the automatic discovering and mounting of local machines connected to the same network. This is especially true if the network includes a lot of Windows computers. Theoretically those machines should be automatically discovered and displayed in Finder under “SHARED” label, but often this is not the case. Anyway in such cases is fortunately possible to connect to a particular device from Finder (once we know its IP address) by choosing “Connect to server…” (cmd+K) and by using the Samba protocol (ie: smb://ip-address). This is however very annoying, because we have to know each ip we want to connect to and type several addresses, so I spent some time to find a way to make this process automatic (because I didn’t find a solution to the original OS X issue) and I realized a shell script which tries to do the job the Leopard should do :)
I’m really a newbie when it comes to shell scripting (and networking too :P) and my script doesn’t work perfectly, anyway it does an acceptable work the most of times and although it doesn’t really solve the problem, it could help a lot.
The script is the following:


# get user name
declare currentuser=$(whoami)

# get mac name
declare macname=$(scutil --get ComputerName)

# save arp command result
declare ipstring=$(arp -a)

# split ipstring into an array by using a regex to match ip addresses
declare -a iplist=($(echo $ipstring | grep -o -E "([0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3})"))

# display addresses found
echo "${#iplist[*]} ip addresses found"

# switch directory to user dir
cd /Users/$currentuser

# for each ip in list try to mount it using smbfs
for ip in ${iplist[@]}
if [ ! -d link-to-$ip ]
echo "creating directory link-to-$ip under /Users/$currentuser"
mkdir link-to-$ip
echo "trying to mount //$macname:@$ip/Public"
mount -t smbfs //$macname:@$ip/Public /Users/$currentuser/link-to-$ip
echo 'folder "link-to-$ip" already exists... skip'

# complete
exit 0

Any comment and suggestion is really appreciated! Thanks

Handling doubleclick on Flex components

Handling a common event like a double click is not so simple as we may assume when it comes to Flex programming.
In fact there are several critical aspects related to this event, first of all we have to set the attribute doubleClickEnabled to true in order to make our components double clickable, and this sounds pretty silly to me. Why should I enable an object to receive an event which is so common and “natural”? This is incoherent from a software design perspective end totally unexpected by the user. Anyway this is not a real problem, because once we know about it we have just to use a setter, but double click is somehow buggy in the framework and its broadcasting can be blocked mysteriously when using certain components. I faced this issue by trying to handle a double click on a DataGrid which makes use of custom item renderers and I tested that by double clicking on the “special cells” (those rendered by my own renderers) the MouseEvent.DOUBLE_CLICK is not dispatched/cacthed. To solve the problem I had to draw an invisible rectangle using the underlying Actionscript graphics API! This is my workaround:

this.graphics.beginFill(0xffffff, 0);
this.graphics.drawRect(0, 0, this.parent.width, this.parent.height);

Finally, it seems that double click is completely ignored by Firefox 3.6 on Mac OS X, but fortunately this seems to been fixed in the last release (3.6.3)