Macs in Chemistry

Insanely great science

 

Copy File to MobileMe and Create email message

MobileMe is no longer available but this script could be modified to save in other online storage facilities.

Whilst Apple now allow you to send a link to a file to another user it requires the use of a web interface, I'm sure it will eventually be built into the Finder but until then this script helps to automate the process. This script is based on a idea from Drew McCormack
The first part of the script asks you to select a file, the next part uses a shell script to compresses it to a zip file if it is not already zipped. It then gets the mobileme name and then copies the zipped file to the Public folder of your MobileMe (.dot mac) account. The final part of the script creates the email that you need to send to the intended recipient.

The Script Menu can be added as a Menu Extra to allow easy access to many AppleScript scripts from the menu bar (Mac OS X ships with several scripts that are ready to use to accomplish some common tasks). You can also add your own scripts to this menu. To enable the Script Menu, run AppleScript Utility (located at /Applications/AppleScript/AppleScript Utility) and check the "Show Script Menu in menu bar" checkbox.

property mobileme_name : ""
property zip_file : "false"
property file_name : ""
property mobileme : ""
set theFile to (choose file with prompt "Select the file:") as text
try
   set text item delimiters to ":"
    set file_name to last text item of theFile
    set text item delimiters to ""
on error
   set text item delimiters to ""
end try

if theFile ends with "zip" then
   set zip_file to "true"
end if

if zip_file is "true" then
   --no need to compress
    set posix_path_theFile_zip to POSIX path of (theFile as text)

else if zip_file is "false" then
   --compress file first
    set posix_path_theFile to POSIX path of (theFile as text)

    set posix_path_theFile_zip to posix_path_theFile & ".zip"
    set file_name to file_name & ".zip"

    do shell script "zip -r -j " & posix_path_theFile_zip & " " & posix_path_theFile & ""
end if

tell application "Mail"
   --this assumes you have an mobileme email account
    --if you don't you will need to set the property  at the start of the script
    try
       set mobileme_name to name of every Mac account
   end try

end tell

set destination_posix to "/Volumes/" & mobileme_name & "/Public"

set destination_web to "http://idisk.mac.com/" & mobileme_name & "-Public/" & file_name

do shell script "cp " & posix_path_theFile_zip & " " & destination_posix

set zip_file to "false"



tell application "Mail"
   
    make new outgoing message with properties {visible:true, subject:"Link to File", content:"The file is here: " & destination_web}

end tell

You can download the script here