2 Answers
2

Although this post is old, I would like to add a few things. I am able to use AppleScripts to send things to my device, but your device needs to be jailbroken (AKA rooted)

Here is how it works:
Run Cydia and install OpenSSH.
On your Mac, run one of the following commands to generate a rsa or dsa ssh key. (I used rsa, because it is newer)

ssh-keygen -t rsa
ssh-keygen -t dsa

It will make a file in your folder /User/[yourusername]/.ssh (also known as ~/.ssh or $HOME/.ssh). Put the id_rsa.pub or id_dsa.pub on your ipad somewhere, perhaps off the root with

scp ~/.ssh/id_rsa.pub root@nameofipad:/

Then log into your ipad (caps sensitive) Ignore all the complaints and just say yes, enter Alpine for the password (if you haven't changed it (change with the command passwd from the ipad's root prompt):

ssh root@nameofipad

Now we are going to take the information stored in this public ssh key and write it to a file on your iPad. First we have to make the folder on the iPad and then write the information.

mkdir ~/.ssh && cat /rsa.pub >> ~/.ssh/authorized_keys

Now the file authorized_keys will contain the key from your Mac. One last important step is to set the correct permissions to the authorized_keys file:

chmod 666 ~/.ssh/authorized_keys

AppleScript

You can now send files to your device via AppleScript. For example, I often edit PDF files with the iOS app iAnnotate PDF. I used iFile on the iPad to identify the folder for the app and I run the following AppleScript to send files to its documents folder:

tell application "System Events"
set ProcessList to name of every process
if "Skim" is in ProcessList then
tell application "Skim"
if document 1 exists then
set the_file to POSIX path of (get file of document 1 as text)
set my_script to "scp -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no " & the_file & " root@JokosiPad.local:/User/Applications/01F8F1E6-BA09-412B-8069-355E7717F409/Documents"
do shell script my_script
end if
end tell
end if
end tell

This script will take whatever file I am reading in Skim (PDF reader) and push it to the iPad. On the iPad (and iPhone) I can start iAnnotate and go to the iTunes Sharing folder and see the file. It is really cool and avoids Apple's stupid iTunes-only crap.

Let me explain the obvious, then the not so obvious:

Obvious

set the script to variable my_script

run myscript

Not Obvious

We tell scp to write the host file information to /dev/null, which basically is a dedicated device that is like a black hole. Everything you write into it is gone. We just need to make scp happy and let it write to something. The other option, -o StrictHostKeyChecking=no makes the connecting not confirm a connection with "Are you sure you want to connect". This allows AppleScript to have unobstructed access to your iPad.

Keep in mind, your iPad host name (mine is JokosiPad) can be found easily by going to the Settings app and clicking general and about. The "Name" record contains the host name to use like JokosiPad.local instead of memorizing the IP Address (which can change).

As far as I can see in iTunes' AppleScript dictionary, there's no support for scripting anything relating to iOS applications. Sorry.

A possible workaround:

If the app, and your Mac, support iCloud, set it up on both and look inside "~/Library/Mobile Documents/" on your Mac.

In there should be a folder corresponding to each app you have iCloud enabled for. You might have to look around the sub-folder structure to see exactly where the files you want to add need to go, but once you figure that out, you can write your script to target that location.

When your script adds a file to that location, it will sync via iCloud. I use this trick all the time to get files into my GoodReader app.

Beware that iOS apps don't always sync to iCloud in the background. In the case of GoodReader I need to open it for the changes to update.