Drag and drop – get file path

Hi

I’m looking to drag & drop a File (pdf) on to a droplet and get the file name, then append this to a path so I can move the file to a folder after I’ve send it via email as an attachment.

I have the email bit sorted but I can get the file to move. When I just hard code the path it works fine but when I use a variable it results in an error.

Any help welcome

thanks

Shane


on open theFiles
	repeat with i from 1 to the count of theFiles
		tell application "System Events"
			set myFileName to name of (item i of theFiles)
			set myDesktopPath to "/Users/AccountName/Desktop/"
			set myFilePath to myDesktopPath & myFileName as text
			
			-- send attachement via mail
			
			tell application "Finder"
				move POSIX file myFilePath to POSIX file "/Users/AccountName/Desktop/Folder" with replacing
			end tell
		end tell
	end repeat
	
end open

Hi,

if the destination folder is a subfolder of the desktop this is much easier

on open theFiles
	repeat with aFile in theFiles -- aFile is an alias specifier which can be used directly in Mail.app
		
		-- send attachement via mail
		
		tell application "Finder"
			move aFile to folder "Folder" of desktop with replacing
		end tell
	end repeat
end open

Hi Stefan

Thanks for the reply.

This does work fine for testing, however the final project will be on a server volume.

I’ve tried making the destination folder as an alias on the desktop but it fails :frowning:

Is there another way of doing this?

thanks

Shane

Then I recommend to use the shell.

The first two property lines contain the server volume name and the full path to the folder. Change it to the proper values. The folder path must start with /Volumes/ followed by the server volume name.

The scripts checks also if the volume is mounted and does not copy the files in case it’s not mounted.


property serverVolumeName : "server"
property serverFolderPath : "/Volumes/server/path/to/folder/"

on open theFiles
	set availableVolumes to paragraphs of (do shell script "/bin/ls /Volumes")
	set serverVolumeIsAvailable to availableVolumes contains serverVolumeName
	
	repeat with aFile in theFiles
		
		-- send attachement via mail
		if serverVolumeIsAvailable then
			set sourceFilePOSIX to quoted form of POSIX path of aFile
			do shell script "/bin/cp " & sourceFilePOSIX & space & quoted form of serverFolderPath
		end if
	end repeat
end open

Hi Stefan

Thanks for this, with a few edits its working a treat :slight_smile:

thanks again

Shane