Folder Action - Does not execute POSIX

Summary:

  1. have a folder action on the desktop
  2. when I add a file
  3. it processes the file

Issue is:

  1. the script stops working after “Step 3” when trying to execute “set theAttachment1 to POSIX file theFile”

question:

  1. What am I doing wrong?
  2. Since it’s a folder action how do see what error it’s generating?

script:


on adding folder items to this_folder after receiving added_items
	try
		repeat with i from 1 to number of items in added_items
			tell application "Finder"
				set this_item to item i of added_items
				set the the_file_name to the name of this_item
				say "Step1"
				display dialog the_file_name
				
				say "Step2"
				set theFile to "/Users/<YOUR-USERNAME>/desktop/testaction/" & the_file_name
				display dialog theFile
				
				say "Step3"
				set theAttachment1 to POSIX file theFile
				display dialog theAttachment1
				say "Step4"
				
				
			end tell
		end repeat
	end try
end adding folder items to

thanks

Try:


on adding folder items to this_folder after receiving added_items
	try
		repeat with i from 1 to count added_items
			
			tell application "Finder" to set the the_file_name to the name of (item i of added_items)
			say "Step1"
			display dialog the_file_name
			
			say "Step2"
			set theFile to (path to desktop as text) & the_file_name
			display dialog theFile
			
			say "Step3"
			tell application "Finder" to set theAttachment1 to file theFile
			display dialog (theAttachment1 as text)
			say "Step4"
		end repeat
		
	on error errMsg number errNum
		tell me
			activate
			display alert errMsg & return & return & "Error number" & errNum buttons "Cancel" cancel button "Cancel"
		end tell
	end try
end adding folder items to

thanks for the help.

This is the error that pops up:

Finder got an error: Can’t get the file “MacintoshHD:Users::desktop:1.jpg”

error number -1728

Is there a file 1.jpg on your Desktop?

Yup thats the problem.

So instead of specifying the desktop how would you specify the specific path?

I didn’t read your original script close enough… does this work?


on adding folder items to this_folder after receiving added_items
	try
		repeat with i from 1 to count added_items
			
			tell application "Finder" to set the the_file_name to the name of (item i of added_items)
			say "Step1"
			display dialog the_file_name
			
			say "Step2"
			set theFile to (path to desktop as text) & "testaction:" & the_file_name
			display dialog theFile
			
			say "Step3"
			tell application "Finder" to set theAttachment1 to file theFile
			display dialog (theAttachment1 as text)
			say "Step4"
		end repeat
		
	on error errMsg number errNum
		tell me
			activate
			display alert errMsg & return & return & "Error number" & errNum buttons "Cancel" cancel button "Cancel"
		end tell
	end try
end adding folder items to

thanks for the patience. hope this clarifies:

–I have a folder action located:
“/Users//desktop/testaction/”

–I want to drop a file into that that folder (ex. 1.jpg)

–I want to take that file then manipulate it (which is working)

The problem is that when it goes to step 3 it isn’t able to located that file do perform the action. The file is located “/Users//desktop/testaction/1.jpg”

Basically I’m trying to figure out

how to specify the path:

works:

/Users//desktop/testaction


set theFile to (path to desktop as text) & "testaction:" & the_file_name

/Users//dir1/dir2/dir3/testaction


??

thanks for the direction. Greatly appreciate it.

working code.


on adding folder items to this_folder after receiving added_items
	try
		repeat with i from 1 to count added_items
			
			tell application "Finder" to set the the_file_name to the name of (item i of added_items)
			say "Step1"
			display dialog the_file_name
			
			say "Step2"
			set theFilePath to "/Users/<username>/desktop/testaction/" & the_file_name
			set theFile to POSIX file theFilePath as string
			--		set theFile to (path to desktop as text) & the_file_name
			display dialog theFile
			
			say "Step3"
			tell application "Finder" to set theAttachment1 to file theFile
			display dialog (theAttachment1 as text)
			say "Step4"
		end repeat
		
	on error errMsg number errNum
		tell me
			activate
			display alert errMsg & return & return & "Error number" & errNum buttons "Cancel" cancel button "Cancel"
		end tell
	end try
end adding folder items to