Help With Droplet (Mac Users accessing files in to Windows Server)

Dudes, sory if im posting this in the wrong place, but is my first meet with Automator / Applescript.

I work at agency, and we use Windows Server, so we have all the file paths like this: O:/CLIENTE/ I:/BADA and things like this. But now we have many mac users here, and i do this little Applescript to easly get the file path by email like (ex: O:/client/nameofclient/nameoffile.fla) all you have to do, is simple copy this text, and execute the APP, and this app open the target Folder at Target server! Work fantastic and very well. This is my script:


(*
Ideia: Bruno Mikoski / Carlos Eduardo de Souza
Desenvolvimento: Bruno Mikoski
Midia Digital 2009
*)
on run
	set strClipboard to the clipboard
	set strFirstLetter to (character 1 of strClipboard)
	set strLastCharacter to (character (length of strClipboard) of strClipboard)
	
	if strLastCharacter = "\\" then
		set strClipboard to (characters 1 thru ((length of strClipboard) - 1) of strClipboard) as string
	end if
	
	set strWindowsPath to (characters 3 thru (length of strClipboard) of strClipboard) as string
	
	
	if strFirstLetter = "O" then
		set targetVolume to "PRODUCAO"
		set targetServidor to "SRVFS-MD"
	else if strFirstLetter = "I" then
		set targetVolume to "CRIACAO"
		set targetServidor to "SRVFS-MD"
	else if strFirstLetter = "K" then
		set targetVolume to "FINANCEIRO"
		set targetServidor to "SRVFS-NOVO"
	else if strFirstLetter = "M" then
		set targetVolume to "PLANEJAMENTO"
		set targetServidor to "SRVFS-NOVO"
	else if strFirstLetter = "N" then
		set targetVolume to "PPC"
		set targetServidor to "SRVFS-NOVO"
	else if strFirstLetter = "P" then
		set targetVolume to "SEO"
		set targetServidor to "SRVFS-NOVO"
	else if strFirstLetter = "Q" then
		set targetVolume to "TECNOLOGIA"
		set targetServidor to "srvad-md"
	else if strFirstLetter = "R" then
		set targetVolume to "DESENVOLVIMENTO"
		set targetServidor to "SRVFS-MD"
	else if strFirstLetter = "S" then
		set targetVolume to "MO"
		set targetServidor to "SRVFS-NOVO"
	else if strFirstLetter = "T" then
		set targetVolume to "PUBLICO"
		set targetServidor to "SRviis-MD"
	else if strFirstLetter = "U" then
		set targetVolume to "FTP"
		set targetServidor to "srviis-md"
	else if strFirstLetter = "V" then
		set targetVolume to "MP3"
		set targetServidor to "srviis-md"
	else if strFirstLetter = "W" then
		set targetVolume to "WWW"
		set targetServidor to "srviis-md"
	else
		display dialog "Servidor não encontrado"
		return
	end if
	
	set AppleScript's text item delimiters to "\\"
	set theTextItems to text items of strWindowsPath
	set AppleScript's text item delimiters to ":"
	set strWindowsPath to theTextItems as string
	set AppleScript's text item delimiters to {""}
	
	set targetMacPath to targetVolume & strWindowsPath
	tell application "Finder"
		activate
		set mountedVolumes to list disks
		if mountedVolumes does not contain targetVolume then
			display dialog "Montando Volume: " & targetVolume
			mount volume "smb://" & targetServidor & "/" & targetVolume
			select targetMacPath
		else
			select targetMacPath
		end if
	end tell
end run


No i want to do a little improvement at this. I Want to get the file path of droped file, or something like that.

The user drop a file into the same application in dock, and the clipboard get the file path in MAC OS: \VOLUME\PRODUCAO\Target Folder\Target File.swf and the windows value: O:/Target Folder/Target File.swf

But i try do that simple doing this:


on open theFile
     display dialog theFile
end open

But this don’t work! can someone help me with the right sintax to get the dropped file into the application?

On open is going to give you a list of dropped items so try something like this

on open fileList
	repeat with i from 1 to count of items of fileList
		display dialog (item 1 of fileList) as Unicode text
	end repeat
end open

Not work for me!

Seen the “on run” handler is executed in the drop action too… When a drop a file into app, its just open the last opened finder window =/

Hi,

here is an improved version of your script which works with lists.
When you drop a file onto the application, the HFS path will be copied to the clipboard


(*
Ideia: Bruno Mikoski / Carlos Eduardo de Souza
Desenvolvimento: Bruno Mikoski
Midia Digital 2009
*)

property volumeNames : "OIKMNPQRSTUVW"
property targetVolumeList : {"PRODUCAO", "CRIACAO", "FINANCEIRO", "PLANEJAMENTO", "PPC", "SEO", "TECNOLOGIA", "DESENVOLVIMENTO", "MO", "PUBLICO", "FTP", "MP3", "WWW"}
property targetServidorList : {"SRVFS-MD", "SRVFS-MD", "SRVFS-NOVO", "SRVFS-NOVO", "SRVFS-NOVO", "SRVFS-NOVO", "srvad-md", "SRVFS-MD", "SRVFS-NOVO", "SRviis-MD", "srviis-md", "srviis-md", "srviis-md"}


on open theFiles
	set the clipboard to item 1 of theFiles as text
end open


on run
	set strClipboard to the clipboard
	set strFirstLetter to first character of strClipboard
	set strLastCharacter to last character of strClipboard
	
	if strLastCharacter = "\\" then
		set strWindowsPath to text 3 thru -2 of strClipboard
	else
		set strWindowsPath to text 3 thru -1 of strClipboard
	end if
	
	if strFirstLetter is in volumeNames then
		set o to offset of strFirstLetter in volumeNames
		set targetVolume to item o of targetVolumeList
		set targetServidor to item o of targetServidorList
	else
		display dialog "Servidor não encontrado"
		return
	end if
	
	set AppleScript's text item delimiters to "\\"
	set theTextItems to text items of strWindowsPath
	set AppleScript's text item delimiters to ":"
	set strWindowsPath to theTextItems as string
	set AppleScript's text item delimiters to {""}
	
	set targetMacPath to targetVolume & strWindowsPath
	tell application "Finder"
		activate
		set mountedVolumes to list disks
		if mountedVolumes does not contain targetVolume then
			display dialog "Montando Volume: " & targetVolume
			mount volume "smb://" & targetServidor & "/" & targetVolume
			select targetMacPath
		else
			select targetMacPath
		end if
	end tell
end run

StefanK amazing work dude! Thanks to teach me about the lists! I haven’t worked with this! But the drop dont work for me yet. Just to make this clear, i work with Automator, add the Execute Applescript, and save this as Application, the name is: Moises.app, and place a shortcut in the dock, so, when i drop a file into the Moises.app in the dock, i want to get in the clippboard the filepath, but not work for me yet =/ seen the on run handler is executed when i drop some file!

Forget Automator. Copy the source text into Script Editor and save the file as application bundle

i do that last time! Work only in my mac, in anothers not run the app =/

But now the whole scrip work fine! Thanks again!

Application bundle (not Carbon!) should work on all Macs, because an Universal Binary is created

Amazing StefanK! Really tank u! Because you show me the lists! But now i have another question for you!

This is my drop:


on open theFiles
	set MacFilePath to item 1 of theFiles as text
	set WindowsFilePath to item 1 of theFiles as text
	
	set AppleScript's text item delimiters to ":"
	set theTextItems to text items of WindowsFilePath
	set AppleScript's text item delimiters to "\\"
	set WindowsFilePath to theTextItems as string
	set AppleScript's text item delimiters to {""}
	
	if item 1 of theTextItems is in targetVolumeList then
		set o to offset of (item 1 of theTextItems) in targetVolumeList as string
		set targetLetter to item o of volumeNames
	end if
	repeat with thisItem in theTextItems
		display dialog thisItem as string
	end repeat
	
	
	
	set the clipboard to "-Windows filepath: " & WindowsFilePath
end open

Now i need, remove the first item in the theTextItems, because o gona overwrite this with the letter of server to get the windows filepath! How i can do that?

Ok! I find it!

Thanks to guys! I Put the code here, maybe this help anther people

(*
Ideia: Bruno Mikoski / Carlos Eduardo de Souza
Desenvolvimento: Bruno Mikoski
Midia Digital 2009
*)

property volumeNames : "OIKMNPQRSTUVW"
property targetVolumeList : {"PRODUCAO", "CRIACAO", "FINANCEIRO", "PLANEJAMENTO", "PPC", "SEO", "TECNOLOGIA", "DESENVOLVIMENTO", "MO", "PUBLICO", "FTP", "MP3", "WWW"}
property targetServidorList : {"SRVFS-MD", "SRVFS-MD", "SRVFS-NOVO", "SRVFS-NOVO", "SRVFS-NOVO", "SRVFS-NOVO", "srvad-md", "SRVFS-MD", "SRVFS-NOVO", "SRviis-MD", "srviis-md", "srviis-md", "srviis-md"}


on open theFiles
	set WindowsFilePath to item 1 of theFiles as text
	
	set AppleScript's text item delimiters to ":"
	set theTextItems to text items of WindowsFilePath
	set AppleScript's text item delimiters to "\\"
	set WindowsFilePath to theTextItems as string
	set AppleScript's text item delimiters to {""}
	
	if item 1 of theTextItems is in targetVolumeList then
		set o to offset of (item 1 of theTextItems) in targetVolumeList as string
		set targetLetter to item o of volumeNames
	end if
	set strFilePath to items 2 thru (theTextItems count) of theTextItems
	
	set AppleScript's text item delimiters to "\\"
	set finalPath to strFilePath as string
	set AppleScript's text item delimiters to {""}
	
	set windowsFinalPath to targetLetter & ":\\" & finalPath
	
	
	set the clipboard to windowsFinalPath
end open


on run
	set strClipboard to the clipboard
	set strFirstLetter to first character of strClipboard
	set strLastCharacter to last character of strClipboard
	
	if strLastCharacter = "\\" then
		set strClipboard to text 3 thru -2 of strClipboard
	else
		set strWindowsPath to text 3 thru -1 of strClipboard
	end if
	
	if strFirstLetter is in volumeNames then
		set o to offset of strFirstLetter in volumeNames
		set targetVolume to item o of targetVolumeList
		set targetServidor to item o of targetServidorList
	else
		display dialog "Servidor não encontrado"
		return
	end if
	
	set AppleScript's text item delimiters to "\\"
	set theTextItems to text items of strWindowsPath
	set AppleScript's text item delimiters to ":"
	set strWindowsPath to theTextItems as string
	set AppleScript's text item delimiters to {""}
	
	set targetMacPath to targetVolume & strWindowsPath
	tell application "Finder"
		activate
		set mountedVolumes to list disks
		if mountedVolumes does not contain targetVolume then
			mount volume "smb://" & targetServidor & "/" & targetVolume
			select targetMacPath
		else
			select targetMacPath
		end if
	end tell
end run

you can’t do “reverse engineering” in this case, because targetVolumeList is a list but volumeNames is a string
To retrieve the volume letter you have to use a repeat loop

on open theFiles
	set MacFilePath to item 1 of theFiles as text
	set WindowsFilePath to item 1 of theFiles as text
	
	set AppleScript's text item delimiters to ":"
	set theTextItems to text items of WindowsFilePath
	set AppleScript's text item delimiters to "\\"
	set WindowsFilePath to theTextItems as string
	set AppleScript's text item delimiters to {""}
	
	set theVolume to item 1 of theTextItems
	if theVolume is in targetVolumeList then
		repeat with i from 1 to count targetVolumeList
			if theVolume is item i of targetVolumeList then
				exit repeat
			end if
		end repeat
		set targetLetter to character i of volumeNames
	end if
	
	set the clipboard to "-Windows filepath: " & targetLetter & "\\" & WindowsFilePath
end open

I have no idea about a windows path because I can’t stand windows, but I’m sure you’ll find the right syntax

Amazing Stefan!

All works pretty with your help!

Now i have more questions! I falling in love with Applescript!

Tell me if this is possible:

Allways someone do the Command+C identy if the First Letter is in the theVolume and the second Letter is : and automatically doing the all process!

This is possible?

Certainly it’s possible but consider, that on the Mac colons are not allowed in file names

Ok! I don’t consider that!
U can show me how identify the Command+C and trigger the application?

I didn’t get what you’re exactly going to do

Think in this process:

: Recived one windows path from a email like: O:/Client/Project/Files;
: User copy this text (O:/Client/Project/Files);
: The Application automatically triggered;
: If the first Character is in the volumeList and the second is the “:” (to be sure the copied text is one filepath);
: Execute the same way to convert the filepath to mac filepath and try open the target file

Can understand? I don’t know if this is crazy or not!

i need some command like:

on press (Command+C)
     
     
     
end press 

on press (Command+C) is not possible, but

¢ the script could read and parse the email itself by a rule in Mail.app
¢ you could call the script with a shortcut (for that a third party tool is required), then the script performs also the ⌘C

if this is not ask to much, u can show me this third party tool?

QuickSilver, Butler, FastScripts, QuicKeys and there are probably a few more

Thanks Stefan, i appreciate all the help you give me! This is very useful!