Thursday, January 6, 2011

More on using MacBook Pro (Snow Leopard) as a Server

You can actually turn a MBP into a WiFi hot spot with the built-in software. Here's the trick:
System Preferences -> Sharing -> Internet Sharing checkbox -> Share your connection from Ethernet
You see AirPort pop up as an option. Click it and click on Airport Options and VIOLA you can configure your MBP to be a router!
You can create a network name, a password, and select level of encryptation. Remember to activate the Internet Sharing checkbox again at the end to "start" the WiFi hotspot.

This was designed to allow you to pipe your ethernet broadband internet connection wirelessly to other devices in the neighborhood, the great thing is even if you do NOT have the ethernet port connected to anything, it will still broadcast a WiFi signal and you can use the local computer name (name.local:8888) to browse to the MAMP server in the MBP.

Why would anyone want to do this? The answer is sometimes you want to browse to the server on a handheld device, even when you are not connected to a local WiFi hotspot. One way is to leave the server behind, at a hotspot, and browse to it using 3G, using methods described previously. But NOW, even if you have a WiFi ONLY device such as an iPod or iPad that doesn't have 3G, if you bring the server with you, you can still run your server scripts on the handheld.

The only problem being: even with the MBP lid closed? The answer is yup, but you have to run a free software called InsomniaX to keep the MBP running even with the lid closed.

Remember, Airport can only go one way at a time. You gotta turn off Internet Sharing to restore Airport to a receiver (instead of a transmitter) once you use it. Crazy.

Friday, December 31, 2010

PHP Script to send PDF file as attachment (requires FPDF object)

function mail_pdf_as_attachment($pdfobj,$faxnumber) {
$pdfdoc = $pdfobj->Output("", "S");
$attachment = chunk_split(base64_encode($pdfdoc));
$to = "destinationaddress@destination.com";
$from = "sourceaddress@source.com";
$subject = $faxnumber;
$message = "See attached pdf file";
$separator = md5(time());
$eol = PHP_EOL;
$filename = "medfax6.pdf";
//headers
$headers = "From: ".$from.$eol;
$headers .= "MIME-Version: 1.0".$eol;
$headers .= "Content-Type: multipart/mixed; boundary=\"".$separator."\"".$eol.$eol;
$headers .= "Content-Transfer-Encoding: 7bit".$eol;
$headers .= "This is a MIME encoded message.".$eol.$eol;
// message
$headers .= "--".$separator.$eol;
$headers .= "Content-Type: text/html; charset=\"iso-8859-1\"".$eol;
$headers .= "Content-Transfer-Encoding: 8bit".$eol.$eol;
$headers .= $message.$eol.$eol;
// attachment
$headers .= "--".$separator.$eol;
$headers .= "Content-Type: application/octet-stream; name=\"".$filename."\"".$eol;
$headers .= "Content-Transfer-Encoding: base64".$eol;
$headers .= "Content-Disposition: attachment".$eol.$eol;
$headers .= $attachment.$eol.$eol;
$headers .= "--".$separator."--";
mail($to, $subject, "", $headers);
}

Dual Formatting of External Hard Drives (PC and MAC)

You can do that?? It turns out, yes.

Plug the drive into a USB port on the mac. Go into Disk Utility (You can find the utility fastest by clicking on the "magnifying glass" shaped icon on the far upper right corner of the screen, which is called Spotlight, and typing Disk Utility.

Then partition the drive, selecting the option to create 2 partitions. This will format the external drive. Select mac formatting for one and MS-DOS FAT for the other. The trick is go go into "Options" after you enter the Partitions tabs and under options select the bottom of the three options, which allows you to create a root directory that will allow the MS-DOS partition. Otherwise, it isn't even an option.

After being done formatting, you will see both partitions on the mac with their assigned names, and if you plug into a PC you will only see the PC partition with its name and letter, like E: as assigned by the PC.

Hosting Content on the World Wide Web on a Laptop

I have a Macbook Pro (MBP) running Snow Leopard. It is connected to the internet through a wireless router. I am running MAMP on it and using it as a server, and I access the server from the iPhone, or the iPad, from WITHIN the LAN (behind the router) via the Wi-Fi connection to that router. Wouldn't it be nice to be able access that same server remotely, from OUTSIDE the LAN, via, say, a 3G connection?

Three steps to doing this:
1. Find out what the IP address is (whatismyip.com)
2. Tell the ROUTER to assign a static IP address to the MBP within the LAN
login to router as admin ->LAN setup->Use Router as DHCP Server->Address Reservation
In my case, I just selected the address it had randomly assigned to make it permanent (192.168.1.18)
You need to know your computer's name and/or mac address to do this, so that you select the correct computer.
3. Then you need to go to port forwarding (still in admin in the ROUTER settings), and assign start port 8888 to forward to end port 8888 on 192.168.1.18.

Finally, step outside the LAN and browse to:
ipaddress:8888/homefolder/index.php
and you are there.

CAUTION: if you do this and leave your server on, your precious MBP is on the world wide web, and can be subject to cyber attack. It helps that the port is not 80, or 8080, which are far more common, but still, take precautions.

Saturday, November 6, 2010

AHK (AutoHotKey) Script to control Dialog Box

iWeb_Init()
SetTitleMatchMode,2
ControlGet,hWnd,Hwnd,,Internet Explorer_Server1,ahk_class Internet Explorer_TridentDlgFrame
pDoc:=IE_GetDocument(hWnd)
pWin := iWeb_DomWin(pDoc)
COM_Invoke(pWin,"Document.all.item['btnID'].click")
COM_Release(pwin)
WinWaitClose, Web Page Dialog
SoundPlay, *64
Com_Release(pDoc)
iWeb_Term()
return

Note: the three indented lines can be replaced with
iWeb_clickDomObj(pDoc,"btnCancel")
accomplishes the same thing but I left the three lines in as a demonstration of how to inject javascript into an AHK script.(There isn't an iWeb function for everything)

Note: You have to #include COM.ahk and iWeb.ahk for this to work, and I commented out the MsgBox line in the COM_Error() function within COM.ahk in order to stop useless error messages from popping up. These libraries were not designed for dialog boxes, but they work, and the error messages just get in the way. Normally calling COM_Error(0) does the same thing except the iWeb functions keep calling COM_Error(1)

Note: ['btnID'] can be replaced with ['387'] or whatever the element index number is.
Notice the WinWaitClose to wait for the Dialog to close, and the Sound alert command. You can also use WinWait to just wait for the Web Browser Object to get focus.

Monday, November 1, 2010

Access to Snow Leopard MAMP server and AHK server from a Windows Domain

For months I have been using a MacBook Pro with OSX 10.4 as a server at work to house my MAMP scripts and AHK scripts. In a previous post I described how to network a MacBook Pro with OS X 10.4 to a windows domain. IT TURNS OUT THOSE INSTRUCTIONS DO NOT WORK FOR SNOW LEOPARD (OS X 10.6). I brought in a back up MacBook Pro and much internet research did not generate a solution for weeks. Until Now.

The secret: On the Mac go to System Preferences>Network>Advanced>WINS>NETBIOS Name. This is where the name of the computer resides. I had been putting the name of the computer into my windows domain machines as specified in System Preferences>Sharing>File Sharing for weeks in a futile effort to connect. It was the wrong name. Thus, for MAMP server the URL is http://netbiosname:8888/MAMP and for the AHK scripts the server is \\netbiosname\macusername. It's that simple. I swear, nobody in the universe knows this little factoid.

Whether it made a difference or not, some other system adjustments were made according to "internet advice". They may be necessary too, I am not sure. All I know is I did them before I found that last little secret and the whole system works very nicely. Those other things included setting the workgroup to to MACPC (not sure why that would matter, all of the windows machines are in a domain, not a workgroup), of course making sure the mac is connected to the correct wireless router with the same network as the other machines (again, not sure if it matters, since most of the machines are connected by ethernet to the network), and I used my "Launcher" on my mac to run "Directory Utility" and put a checkmark in the "Activate Directory" box. For what it's worth. And I went into aforementioned sharing and did everything in my previous post, plus activated privileges for guests, added myself as a user, activated ftp, etc. (Note- the "Windows Sharing" pane present in 10.4 doesn't exist in 10.6) Have fun with this. Networking is a real bear.

Sunday, September 5, 2010

Examine Mouse Positions in AHK

A truly useful script to have running while writing Mousey Scripts.
I have mine set to z

CoordMode, Mouse, Screen
MouseGetPos, X, Y
MsgBox %X%, %Y%
return