Need Help with Transmit AppleScript

I’ve been trying to create an AppleScript that will automatically rename a file, create a TinyURL for it’s location and upload the file to my server. I’m so close, except Transmit returns the result “false” when given the name of the file to upload. I’m sure I’m missing something obvious.


tell application "Finder"
	set theFile to item 1 of (get selection)
	set TheName to name of theFile
	set duplicatedFile to duplicate theFile
end tell
set capName to do shell script "/bin/echo " & quoted form of TheName & " | /usr/bin/awk '{for(i=1;i<=NF;i++)sub(/./,toupper(substr($i,1,1)),$i)}1' | tr -cd [:alnum:]_. "
tell application "Finder"
	set name of duplicatedFile to capName
end tell
set the clipboard to "http://www.domain.com/Share/" & capName

tell application "Safari"
	set longURL to the clipboard
end tell
set curlCMD to "curl --stderr /dev/null \"http://tinyurl.com/api-create.php?url=" & longURL & "\""
set tinyURL to (do shell script curlCMD)
set the clipboard to tinyURL

tell application "Transmit"
	set SuppressAppleScriptAlerts to true
	tell current session of document 1
		connect to favorite with name "My Server"
		set their stuff to "Share"
		upload item capName
		quit application "Transmit"
	end tell
end tell

tell application "Finder"
	move selection to trash
end tell

Hi,

I don’t use Transmit, but you try to upload a string (capName) instead of a file.
btw: You don’t need the first clipboard transfer nor Safari to set the variable
Try:


tell application "Finder"
	set theFile to item 1 of (get selection)
	set TheName to name of theFile
	set duplicatedFile to duplicate theFile
end tell
set capName to do shell script "/bin/echo " & quoted form of TheName & " | /usr/bin/awk '{for(i=1;i<=NF;i++)sub(/./,toupper(substr($i,1,1)),$i)}1' | tr -cd [:alnum:]_. "
tell application "Finder"
	set name of duplicatedFile to capName
end tell

set longURL to "http://www.domain.com/Share/" & capName
set curlCMD to "curl --stderr /dev/null \"http://tinyurl.com/api-create.php?url=" & longURL & "\""
set tinyURL to (do shell script curlCMD)
set the clipboard to tinyURL

tell application "Transmit"
	set SuppressAppleScriptAlerts to true
	tell current session of document 1
		connect to favorite with name "My Server"
		set their stuff to "Share"
		upload item (duplicatedFile as alias)
		quit application "Transmit"
	end tell
end tell

Note: you can upload files via FTP also with curl

Thanks for the suggestion regarding Safari, I thought it seemed unnecessary, but since I built everything in pieces and it was working, I decided not to mess with it.

When I try your script, I get the error, Can’t make «class docf» “Test File copy.png” of «class cfol» “Desktop” of «class cfol» “username” of «class cfol» “Users” of «class sdsk» of application “Finder” into type alias."

Thanks for the help.

I’m trying to upload the file using curl, but I’m getting the error message, “Finder got an error: curl: no URL specified! curl: try ‘curl --help’ or ‘curl --manual’ for more information”


tell application "Finder"
	set theFile to item 1 of (get selection)
	set TheName to name of theFile
	set duplicatedFile to duplicate theFile
end tell
set capName to do shell script "/bin/echo " & quoted form of TheName & " | /usr/bin/awk '{for(i=1;i<=NF;i++)sub(/./,toupper(substr($i,1,1)),$i)}1' | tr -cd [:alnum:]_. "
tell application "Finder"
	set name of duplicatedFile to capName
	set curlFTP to "curl -T " & capName & "ftp://username:password@ftp.domain.com/path/"
	do shell script curlFTP
end tell

set longURL to "http://www.domain.com/Share/" & capName
set curlCMD to "curl --stderr /dev/null \"http://tinyurl.com/api-create.php?url=" & longURL & "\""
set tinyURL to (do shell script curlCMD)
set the clipboard to tinyURL

You did it again: you’re going to upload just a file name, not a file path


tell application "Finder"
	set theFile to item 1 of (get selection)
	set TheName to name of theFile
	set duplicatedFile to (duplicate theFile) as alias
end tell
set capName to do shell script "/bin/echo " & quoted form of TheName & " | /usr/bin/awk '{for(i=1;i<=NF;i++)sub(/./,toupper(substr($i,1,1)),$i)}1' | tr -cd [:alnum:]_. "
tell application "Finder" to set name of duplicatedFile to capName
set curlFTP to "curl -T " & quoted form of POSIX path of duplicatedFile & space & quoted form of ("ftp://username:password@ftp.domain.com/path/" & capName)
do shell script curlFTP

set longURL to "http://www.domain.com/Share/" & capName
set curlCMD to "curl --stderr /dev/null \"http://tinyurl.com/api-create.php?url=" & longURL & "\""
set tinyURL to (do shell script curlCMD)
set the clipboard to tinyURL

I’m getting a similar error as before:

Can’t make «class docf» “test file copy.png” of «class cfol» “username” of «class cfol» “Users” of «class sdsk» of application “Finder” into type alias.

I edited the script, have you tried the latest version?

I really appreciate your effort. Thank you.

I’m getting this error now:

Can’t make quoted form of POSIX path of «class docf» “Test File copy.png” of «class cfol» “Desktop” of «class cfol» “username” of «class cfol» “Users” of «class sdsk» of application “Finder” into type Unicode text.

Also, I find it interesting that it says, “Can’t make quoted form of POSIX path of «class docf» “Test File copy.png”” because the file name has been changed to TestFile.png

I’ve just tested this version, which works fine

tell application "Finder"
	set theFile to item 1 of (get selection)
	set TheName to name of theFile
	set duplicatedFile to (duplicate theFile) as alias
end tell
set capName to do shell script "/bin/echo " & quoted form of TheName & " | /usr/bin/awk '{for(i=1;i<=NF;i++)sub(/./,toupper(substr($i,1,1)),$i)}1' | tr -cd [:alnum:]_. "
tell application "Finder" to set name of duplicatedFile to capName

set curlFTP to "curl -T " & quoted form of POSIX path of duplicatedFile & space & quoted form of ("ftp://user:pass@ftp.myServer.com/path/" & capName)
do shell script curlFTP


set longURL to "http://www.domain.com/Share/" & capName
set curlCMD to "curl --stderr /dev/null \"http://tinyurl.com/api-create.php?url=" & longURL & "\""
set tinyURL to (do shell script curlCMD)
set the clipboard to tinyURL

Thank you! Thank You! Thank You!