I’m new to applescript and after browsing around have found many people trying to do things similar to this. I would like to be able to drop a file onto an applescript application and then have the file automatically copied to my iDisk and then add the URL of the new location to the clipboard. For example [url=http://www.me.com/main/uploads/filename.jpg]http://www.me.com/main/uploads/“filename.jpg”[/url]. So far using a combination of automator and applescript I have created a script that will upload the file and output the link in a dialog box which I can then manually copy.
I have several questions:
How to do I incorporate the input of a file which I physically drop onto a script thereby launching the script?
How do copy this file name to the clipboard?
Is there a way to tell the OSX to sync my iDisk during a script?
Here is what I have so far. I’ve been using the automator “copy finder items” to move the files to my iDisk which seems to work just fine but I still have to manually update the sync
tell application "Finder"
mount volume "[url=http://idisk.me.com/my_username/]http://idisk.me.com/"my_username/[/url]" as user name ¬
"my_username" with password "my_password"
end tell
set first_file to input
tell application "Finder" to set file_name to (name of first_file)
set thepath to first_file as text
set theposix to POSIX path of thepath
set first_url to "http://homepage.mac.com/my_username/uploads/"
set the clipboard to (first_url & file_name)
display dialog "URL" default answer first_url & file_name buttons ["Cancel", "Connect"] default button 2
return first_file
Model: iMac 2.8 ghz 500GB, PowerBook 1.5 ghz 60GB
Browser: Safari 528.16
Operating System: Mac OS X (10.5)
I just noticed a mistake. The functional version reads like this:
tell application "Finder"
mount volume "[url=http://idisk.me.com/my_username/]http://idisk.me.com/"my_username/[/url]" as user name ¬
"my_username" with password "my_password"
end tell
set first_file to input
tell application "Finder" to set file_name to (name of first_file)
set thepath to first_file as text
set theposix to POSIX path of thepath
set first_url to "http://homepage.mac.com/my_username/uploads/"
set the clipboard to (first_url & file_name)
display dialog "URL" default answer first_url & file_name buttons ["Cancel", "Connect"] default button 2
return first_file
The only difference between this and what I am trying to achieve is that this does not allow me to drop a file onto the scrip and launch the script, nor does it output the new link to the clipboard. But rather a textbox
property iDiskPassword : "¢¢¢¢¢"
property iDiskName : ""
on open theItems
set iDisk to mountiDisk()
repeat with oneItem in theItems
set fName to name of (info for oneItem)
set destinationPath to POSIX path of iDisk & "uploads/" & fName
do shell script "/bin/mv " & quoted form of POSIX path of oneItem & space & quoted form of destinationPath
set the clipboard to "http://homepage.mac.com/" & iDiskName & "/uploads/" & fName
end repeat
end open
on mountiDisk()
set iDiskName to do shell script "/usr/bin/defaults read -g iToolsMember"
try
mount volume ("http://idisk.mac.com/" & iDiskName) as user name iDiskName with password iDiskPassword
on error error_message number error_number
if error_number is not in {-55, -128} then
display dialog error_message buttons {"Cancel"} default button 1
end if
end try
repeat
try
tell application "Finder" to return (1st disk whose name is iDiskName and format is WebDAV format) as alias
end try
delay 1
end repeat
end mountiDisk