Showing posts with label iPhone. Show all posts
Showing posts with label iPhone. Show all posts

2008-03-13

local copy/paste on the Touch with iCopy

First off, I'd like to excoriate Apple for their egregious omission of copy/paste functionality on the iPhone and iPod Touch. Yes, you heard that right - there is no way to copy and paste text on the Touch or iPhone, though we assume it's coming in OS update 2.0 in June. That say, there are some kludgey solutions available. Here's one:



Preston Monroe has released iCopy, a Safari bookmarklet that will copy text from a web page and paste it into another web page. (Actually, he uses an intervening step so the process is actually copy, paste, paste). That's a good start, but what if you want to copy text from a file on your Touch to a website, or vice-versa? Well, I've written a solution for that: localCopyPaste, available from my .Mac public folder as localCopyPaste.zip.

Here's how to install and use it. I'll assume you have some basic command-line skills, so please don't write me asking how to change directories or open a Terminal session. If that's beyond you, you'll probably find the installation and usage to be too inconvenient anyway. With that said, here goes.

Installation:
  1. Install Cydia, AFP, TextEdit from Installer.App
  2. Install Python, wget, OpenSSH, Terminal (Term-vt100) from Cydia.
  3. Optionally install 1.1.3/4 Safari patch to allow you to open files on your Touch using Safari.
  4. On your desktop, install Putty (for Windows). If using a Mac or Linux, you already have ssh. Connect to your Touch (or iPhone) after determining its IP address (check Setting > Wireless > name of network you're connected to). Let's assume it's 192.168.0.94. To connect, type "ssh -l root 192.168.0.94", then log in with the appropriate password (default is 'alpine').
  5. Switch to your Documents folder: "cd /User/Media/Documents" (or any other preferred location).
  6. Install the web.py web application framework: "easy_install web.py". This should fetch it from python.org and install it.
  7. Now unzip localCopyPaste.zip on your desktop and copy over to your Touch's /User/Media/Documents folder. On the Mac, you can use Finder to do this, after using 'Connect to Server' and specifying 'afp://192.168.0.94' as the desired location; or, you can use Fugu and its built-in SCP tool. On Windows, use the excellent WinSCP application for this.
  8. Go back to your SSH client and make the copypaste.sh and killcopypaste.sh files executable with "chmod 0755 *.sh"
  9. Now you will start a local webserver on port 8080 serving up a special page so that iCopy can copy from it or paste to it: in your SSH window, type "./copypaste.sh". If all goes well, after a second or two you should see "running with PID 21644" (or some other process number). Then you will see a second line "http://0.0.0.0:8080/" which indicates that the webserver is accepting local connections on port 8080. Press Enter to get your command prompt back. You can now close your SSH window and break the connection between the desktop and the Touch. If you get an error spew ending with "socket.error: socket already in use", this means that you have tried to start a second copy of the webserver, or another webserver is running on that port.
  10. If you want to stop the local webserver later, either open another SSH connection to the Touch, or open a local Terminal session on the Touch, and go back to the installation directory. Type "./killcopypaste.sh".

Usage:
  1. Put the text you want to copy into a local file in /User/Media/Documents. By default, the local copy websersver will look for a file called copy.txt in this folder. Similarly, the webserver will place pasted text into a file called paste.txt in this folder.
  2. Now use iCopy to copy text from a website to your Touch (by default, into paste.txt), or to copy text from copy.txt on your Touch and then paste it to some remote website. Remember that iCopy requires you to Copy - Paste - Paste.
Good luck! Comment, suggestions?

Update:

I did all my testing on my Touch while it was connected to my desktop PC or Mac via SSH. And I started my web application through that SSH connection. I've discovered that as soon as I break the SSH connection, the web application stops. That's no good! One solution is to start and stop the app through the BossPrefs utility, as it's used for a number of other server services. I'm still working on that and should have something in a few days.

2008-03-10

Put your owner info on your iPhone / Touch home screen

One of the useful features of my old Palm PDA was the Owner Info icon. The idea was that if someone picked up your mislaid PDA and turned it on, she might see and tap on the Owner icon and then know:
- who the owner was and how to reach him
- what reward, if any, was being offered
Sure, you can just paste a sticker on the back of your device with your info on it, but after a few weeks it'll be illegible. Having the information on the device itself, on the main screen, is a more reliable way of ensuring that it's there when it's needed.

Since moving to an iPod Touch as my new PDA, I've missed this simple feature, but found a workaround for it. Here's how to do it:


  1. First off, jailbreak your iPhone or Touch (or wait for software update 2.0 in June). If you want to jailbreak, just visit ziphone.org and download the handy utility. The Windows version crashed on me, but the Mac version succeeded in about 3 minutes. This process will put Installer.app on your device.
  2. Open Installer.app and look for the 1.1.4 Safari Patch. This will allow Safari to open files on your device using a file:// type of URL.
  3. While you're at it, install the OpenSSH server, which will allow you secure access to your device. Note that you may need to apply a fix (via the method below) to your /etc/termcap file in order to be able to log in via SSH (at least, this fix is required for opening a local Terminal window).
  4. Next, connect your device to your local wireless network, and note the IP address it is assigned (e.g. 192.168.0.77). On your Mac, you can then connect to your device using "afp://192.168.0.77" for direct Finder access, or use Fugu. On a Windows PC, grab a copy of WinSCP and connect to that same IP address.
  5. Now open a text editor on your PC and copy the file below, editing as required to meet your needs. I included a picture of me sized around 150x150 pixels: seeing the owner's picture may encourage the finder to return the device, I figure. Save this file as owner.html.
  6. Now copy the owner.html and the picture file, if any, to your device. I put them in /User/Media/Documents.
  7. Open Safari and browse to "file:///User/Media/Documents/owner.html". Adjust the page zoom until your message fills the screen. You may need to edit your source document several times to get it right, copying the latest version each time over to your device and then hitting Reload in Safari to see your changes.
  8. When it all looks nice, hit the + icon at the bottom of the screen and select "Add to Home Screen"; an icon of the owner.html page will be placed on the home screen with the caption "Owner Info" underneath it.

I'm leaving as an exercise for the reader to create a little application that will do all of this for you right on your device!

Contents of owner.html (edit to suit your taste):

<html>
<head><title>Owner Info</title>
</head>
<body><h1>Hello!</h1>
<p>
<table width="100%" border="0">
<tr><td width="150"><img src="./Avatar147x160.jpg" width="140" height="160"></td>
<td>Please return to:<br>
Owner name<br>
Owner email address<br>
Owner phone number<br>
City, Country</td></tr></table>
<p><span><font size="+1">
Thank you for finding my _device-model_.<br>
I've spent a lot of time setting it up<br>
to my liking, and will gladly offer a<br>
reward for its safe return.<br>
Thank you!</font></span></p>
</body>
</html>