Search This Blog

Loading...

Friday, August 28, 2009

Download, back up, and upload Google Docs files

You can download, back up, and upload documents from your Google Docs account using a little Terminal magic. Prerequisites:
  1. gdata-python-client 2.0.1 - download page
  2. gdatacopier 1.0.2 - download page
Installation:
  1. Download the prerequisites. Decompress each of the downloads.
  2. Install gdata-python-client:
    $ cd gdata-2.0.1

    $ sudo python setup.py install
Patch:

The current gdatacopier download has a small bug in it, and it needs to be patched to work properly. Open the file gdatacopier.py in the app's folder, and locate line 555. On that line, change this...
item_list.append({'title': entry.title.text.encode('UTF-8'),
...to this...
item_list.append({'title': entry.title.text,
Save the file and quit the editor.

Usage:

By default, gdatacopier will download your spreadsheets and text documents in the OpenOffice format (.ods and .odt, respectively). TextEdit does a pretty good job of opening the text (.odt) documents, but I was unable to find anything free that could open the spreadsheet (.ods) documents, so you may want to specify a specific format when downloading your documents.

Variables
  • $DIR = local download location
  • $USERNAME = Google email (e.g. someone@gmail.com)
  • $GOOGLEID = Google docs id number. You can find the document's Google ID by using the list- commands below. Make sure to copy only the Google ID from the listing -- not the date or other data. Also make sure to enclose the Google ID in quotes in your command.
Examples:
  • Display gdatacopier help: ./gdoc-cp.py --help
  • Back up all Google Docs in OpenOffice format: ./gdoc-cp.py --username someone@gmail.com --export default --google-id all --local $DIR
  • Back up all Google Docs spreadsheets in Excel format: ./gdoc-cp.py --username $USERNAME --export xls --google-id spreadsheets --local $DIR
  • Back up all Google Docs Text in Rich Text format (retains most formatting): ./gdoc-cp.py --username $USERNAME --export rtf --google-id documents --local $DIR
  • Back up all Google Docs in PDF Format: ./gdoc-cp.py --username $USERNAME --export pdf --google-id all --local $DIR
  • List all Google Docs: ./gdoc-cp.py --username $USERNAME --list-all
  • List all Google Docs spreadsheets: ./gdoc-cp.py --username $USERNAME --list-sheets
  • List all Google Docs text documents: ./gdoc-cp.py --username $USERNAME --list-docs
  • Find a specific Google Doc by title: ./gdoc-cp.py --username $USERNAME -p $PASSWORD --list-all | grep Casserole
  • Download a specific text document in TextEdit (rtf) format: ./gdoc-cp.py --username $USERNAME --export rtf --google-id "$GOOGLEID" --local "OUTPUT_FILENAME.rtf"
  • Download a specific spreadsheet document in Excel (xls) format: ./gdoc-cp.py --username $USERNAME --export xls --google-id "$GOOGLEID" --local "OUTPUT_FILENAME.xls"
  • Download a specific document in PDF format: ./gdoc-cp.py --username $USERNAME --export pdf --google-id "$GOOGLEID" --local "OUTPUT_FILENAME.pdf"
  • Upload a document to Google Docs (rtf, txt, xls, doc): ./gdoc-cp.py --username $USERNAME --import --local "INPUT_FILENAME" --title "OPTIONAL_TITLE"
Notes:
  • A password can be hardcoded into the command if desired.
  • The current version of gdatacopier (1.0.2) is unable to upload all the file types supported by Google Docs (including PDF, html, docx, and possibly others -- that's all I tested).
  • gdatacopier-1.0.3 in the repository appears to offer support for presentations and some other options including folders (aka tags). If you want to play around with it you can get it here. (The code must be patched as above, plus also patch line 289: download_document(document_id, file_format, local_path, write_metadata) -- change that to download_item(document_id, file_format, local_path, write_metadata).)
  • A future v2.0 is in the works, hopefully soon.
  • Maybe a crafty AppleScript Studio programmer could write a GUI for all this.

Apple to release Mac OS X Snow Leopard on August 28



Mac OS X Snow Leopard


The world's most advanced operating system. Finely Tuned.
Available on August 28, 2009.



Apple announced Monday that Mac OS X 10.6 Snow Leopard will go on sale Friday, August 28 at Apple's retail stores and Apple authorized resellers, and that Apple's online store is now accepting pre-orders.

Wednesday, July 15, 2009

Use web proxy auto-discovery in Safari

Unlike most browsers, Safari doesn't have a setting to use WPAD (web proxy auto-discovery) in OS X. However, there is a way to ask Safari to automatically detect the network's proxy settings, but only if your network administrator has configured WPAD on your network.

This auto-detect feature works through DNS. The browser looks for a host named "wpad" and if it exists, loads its settings by accessing a file named "wpad.dat" via HTTP. To use DNS-based WPAD with Safari on OS X, follow these steps:
  • In Safari, choose Safari » Preferences
  • Click on the Advanced icon
  • Click on the Proxies » Change Settings button
  • In the Configure Proxies dropdown menu, select Using A PAC File
  • In the PAC File URL field, enter http://wpad/wpad.dat
  • Click on OK
  • Click on Apply
Again, this is only helpful if your network administrator has set up a proxy to be auto-configured. If you're on a network that doesn't have such a setup, Safari will still work but much, much slower. To find out if your network supports proxy auto-detection, visit http://wpad/wpad.dat in your web browser. If your network supports WPAD, then your browser will download the file "wpad.dat" (which you can just delete). If it's not supported, you'll get an error message.

Firefox 3.5's Three-Finger Swipes

In addition to the previous "twist" gestures which are disabled by default, Firefox 3.5 also ships with default enabled multi-touch swipe inputs:
  • Three-finger swipe up: Home key (top of the page)
  • Three-finger swipe down: End key (bottom of the page)
  • Three-finger swipe left: Browse back
  • Three-finger swipe right: Browse forward
These can be edited by entering about:config in the address bar. Enter swipe in the filter box.

Tuesday, July 7, 2009

Remove Safari history files on logout via shell script

If you'd like to remove your Safari history files when you log out, first create the following shell script:
#!/bin/bash

# Point this at your user folder.
useroot=/Users/your_user

# Clear Safari History (except for bookmarks).
rm -f $useroot/Library/Safari/Downloads.plist $useroot/Library/Safari/History.plist
rm -f $useroot/Library/Safari/HistoryIndex.sk $useroot/Library/Safari/TopSites.plist
rm -f $useroot/Library/Safari/WebpageIcons.db $useroot/Library/Safari/LastSession.plist

# Add any additional clean-up here.
Save the script somewhere, make it executable, and because it runs as root, make sure it is protected from modification. Then copy and paste this command into Terminal, modifying it to point to wherever you put the above script:

sudo defaults write com.apple.loginwindow LogoutHook "/Users/your_user/scripts/privacy.sh"

To be complete, you should also visit Safari's Preferences, open the AutoFill tab, and clear all of the checkmarks (Safari then won't remember passwords and forms).

Make SMB shares appear in Devices section of Finder sidebar

It was driving me nuts that SMB shares from my Windows server would not reappear under DEVICES in the sidebar. However, I then figured out that I can do this:
  1. Open System Preferences » Network
  2. Click the network interface you use for the shares
  3. Click on the Advanced button at lower right
  4. Click on WINS tab, and manually enter the workgroup name of the server
  5. Click the '+' under the WINS Servers list
  6. Enter the IP of the server (you are using static IP on your server, right?)
  7. Click OK, Apply, etc. until you're done
The next time I dragged a mounted share to Devices, it then showed up there automatically after the next unmount/mount. My shares seem to mount much faster now, as well. Now if only I could find a way to increase the transfer speed...sigh.

Mac OS X 10.5: Wake a sleeping Mac with via Automator

I have a Mac mini in my living room hooked up to my TV. I wanted to be able to control the mini from my iMac in my office. Using Screen Sharing built into Leopard, it's a simple click of the mouse to do this. With a little Automator love, I created a simple workflow that turns the Screen Sharing step into a click of an icon in the dock.

However, even with the power efficiency of the 2009 Mac mini, I don't want to leave it on 24/7. After searching through several solutions that used Python and shell scripting (neither of which I know or could make work), I found this nifty this nifty Applescript from Mark Muir that I adapted to solve my problem. Here's my modified code:
(*
Script adapted from Wake on WAN - by Mark Muir (2008-04-01)
http://forums.dealmac.com/read.php?4,2751523
*)

property MAC_address : "00:25:4b:9f:63:c8"
property WAN_IP_address : "255.255.255.255"

on run
set command to "/usr/bin/php -r " & quoted form of ("$mac = " & quoted form of MAC_address & "; $ip = " & quoted form of WAN_IP_address & "; " & "
$mac_bytes = explode(\":\", $mac);
$mac_addr = \"\";
for ($i=0; $i<6; $i++)
$mac_addr .= chr(hexdec($mac_bytes[$i]));
$packet = \"\";
for ($i=0; $i<6; $i++) /*6x 0xFF*/
$packet .= chr(255);
for ($i=0; $i<16; $i++) /*16x MAC address*/
$packet .= $mac_addr;

$port = 9;
$sock = socket_create(AF_INET, SOCK_DGRAM, SOL_UDP);
socket_set_option($sock, SOL_SOCKET, SO_BROADCAST, TRUE);
socket_sendto($sock, $packet, strlen($packet), 0, $ip, $port);
socket_close($sock);
")
do shell script command
end run
You'll need to replace the MAC_address property with the MAC address (found in the Networking System Preferences panel) of the machine you'd like to wake. I then wrapped this script in a simple Automator application to make it a true one-click operation. You can read all the details, and download a copy of the Automator application, in this entry in my blog.

I've mirrored the Automator application here on Mac OS X Hints, in case the original post ever goes away. While I haven't tested this one, I'm pretty sure you could replace the full script shown above with a call to the free Wakeonlan perl script, which was described in this older hint.