attach action to folder "paththefolder:" using "youractioscript.scpt"

Hello

After 2 days of research, I need your help for this Applescript:rolleyes:
I would like to create an application that attach a script to a particular folder and I don t know by advance the name of the hard drive and the user
the problem is that this function doesn’t work
tell application “System Events” to attach action to theLocation2 using “~/Desktop/Myscript.scpt”

Result:
error “System Events got an error: Can’t make "/Users/gsk/Library/Application Support/ArtProMac/My ArtProMac Content" into type specifier.” number -1700 from “/Users/gsk/Library/Application Support/ArtProMac/My ArtProMac Content” to specifier

FYI the script will be on the desktop and this application too

Thank you very much for your help

tell application “System Events”
set theStartupdisk to name of startup disk
set theUser to name of current user
set theLocation to theStartupdisk & “/Users/” & theUser & “/Library/Application Support/ArtProMac/”
set theLocation2 to theLocation & “My ArtProMac Content” as text

end tell

tell application “System Events” to attach action to theLocation2 using “~/Desktop/Myscript.scpt”

tell application “System Events” to set folder actions enabled to true

Also
I would like to put a condition

if system 10.9 or later
set theLocation to theStartupdisk & “/Users/” & theUser & “/Library/Containers/com.artpromac.com/Data/Library/Application Support/ArtProMac/”

else
set theLocation to theStartupdisk & “/Users/” & theUser & “/Library/Application Support/ArtProMac/”

Model: imac
Browser: Safari 600.1.25
Operating System: Mac OS X (10.8)

Hi,

you’re mixing up HFS paths with POSIX paths

HFS paths are colon separated and start always with a disk name
POSIX paths are slash separated and start always with a slash representing the startup volume

AppleScript does not recognize the tilde as a replacement for the current user’s home folder. you have to provide the full path or a relative path.

For example this syntax is wrong because a POSiX path does not start with a disk name


tell application "System Events"
	set theStartupdisk to name of startup disk
	set theUser to name of current user
	set theLocation to theStartupdisk & "/Users/" & theUser & "/Library/Application Support/ArtProMac/"
	set theLocation2 to theLocation & "My ArtProMac Content" as text
end tell

a vaild syntax with a relative path is

set theLocation2 to POSIX path of (path to application support folder from user domain) & "ArtProMac/My ArtProMac Content

"

(1) You may use :

if (system attribute "sys2") > 9 then
	set theLocation to (path to library folder from user domain as text) & "Containers:com.artpromac.com:Data:Library:Application Support:ArtProMac:"
else
	set theLocation to (path to application support folder from user domain as text) & "ArtProMac:"
end if

(2) Are you sure that
tell application “System Events” to attach action to theLocation2 using path2script
is a valid command ?
I don’t find such an action in the System Events dictionary.
More, I don’t see it in the scripts delivered by Apple to attach scripts.
Look in : SSD 500:Library:Scripts:Folder Actions:

I extracted the relevant instructions from the Apple sample script ::

set targetFolder to (path to desktop folder as text) & "target:"

tell application "System Events"
	set folderName to name of folder targetFolder
	if not (exists folder action folderName) then
		make new folder action at end of every folder action with properties {path:targetFolder}
	end if
	# The script is supposed to be stored
	# in (path to library folder from local domain as text) & "Scripts:Folder Action Scripts:"
	# or
	# in (path to library folder from user domain as text) & "Scripts:Folder Action Scripts:"
	make new script at end of every script of folder action folderName with properties {name:"Image - fixed 800x600.scpt"}
end tell

Yvan KOENIG (VALLAURIS, France) jeudi 27 novembre 2014 12:26:26

A big Thanks to Stephan and un grand merci à Yvan;-)

The perfect sentence that i’m looking for
“set theLocation to (path to application support folder from user domain as text) & “ArtProMac:””

pour la commande tell application “System Events” to attach action to theLocation2 using path2script

je l’ai eu sur des forums effectivementsans me soucier si elle était valide
c’est pour ça que j ai passé 2 jours à essayer de la faire marcher :slight_smile:

Merci mille fois

Another 2 questions
I used choose folder and the default location

how to automatically validate the button after 5 sec ?

set TempPhotos to choose folder with prompt “selectionner le dossier” default location alias theLocation

I tried

tell application “System Events” to key code 36
end tell

////////////
tell application “System Events”
tell process “Finder”
keystroke return
end tell
end tell

////////////
set TempPhotos to choose folder with prompt “selectionner le dossier des photos” default location alias theLocation giving up after 5

nothing is working :frowning:

How to send by email a particular file .png in the folder theLocation ?

I tried

set TempPhotos to choose folder with prompt “selectionner le dossier des photos” default location alias theLocation
set msgText to “My Test”

tell application “Finder” to set attchList to (every item of TempPhotos) as alias list

set theSender to “Me”
set recipName to “You”
set recipAddress to “xxx@gmail.com

tell application “Mail”

set newmessage to make new outgoing message with properties {subject:"Mes photos", content:msgText & return & return, visible:false}
tell newmessage
	set visible to false
	set sender to theSender
	make new to recipient with properties {name:recipName, address:recipAddress}
	try
		repeat with attach in attchList
			make new attachment with properties {file name:(contents of attach)}
		end repeat
		
		--For Demo  
		set visible to true
	on error errmess -- oops
		log errmess -- log the error
		set message_attachment to 1
	end try
end tell
--send newmessage

end tell
–Send Email

Thanks