Path to me copy a file, where am I going wrong?

I’m trying to copy a file from the Resources of the app, over to another location.

Using the method below how can I make it copy?
I’m struggling with the string/alias/POSIX path?

I get confused on it every time.


set heliconFocus to (path to me as string)'s POSIX path & "Contents/Resources/Scripts/0_HeliconHotFolder.scpt"

set WorkFlow to make folder at (path to home folder) with properties {name:"Workflow"}
set thefolderactions to (make folder in WorkFlow with properties {name:"Folder Actions"}) as string
copy file heliconFocus to folder thefolderactions

Hello.

You are having a posix path which can’t be copied directly with an AS command, though I thought you’d need to use either System Events or Finder, I think System Events will work with a posix path, whereas finder willl not.

If you want to use finder to duplicate the file for you, then you must duplicate the posix file .

Hi,

copy is no valid command to copy items (assuming you’re talking to the Finder).
The proper command is duplicate


set heliconFocus to (path to me as text) & "Contents:Resources:Scripts:0_HeliconHotFolder.scpt" -- HFS path string
tell application "Finder"
	set WorkFlow to make folder at home with properties {name:"Workflow"} -- Finder folder specifier
	set thefolderactions to (make folder in WorkFlow with properties {name:"Folder Actions"}) -- Finder folder specifier
	duplicate file heliconFocus to thefolderactions -- file is needed to make a Finder file specifier
end tell

AppleScript expects HFS paths (colon separated)

PS: you will get an error in case one of the folders exists

I’m still getting an error

Result:
error “Finder got an error: Can’t set folder "Folder Actions" of folder "Workflow" of folder "Matthew" of folder "Users" of startup disk to file "FusionD:Users:Matthew:Desktop:Installer.app:Contents:Resources:Scripts:0_HeliconHotFolder.scpt".” number -10006 from folder “Folder Actions” of folder “Workflow” of folder “Matthew” of folder “Users” of startup disk

It appears that the path of the folder is still wrong?

Got it working now, I think it was conflicting with other items in the tell application “finder” part.

So using exactly as your code, no issues. Many thanks

Matt

It’s still not working? it did the first time, I deleted the items and tried again but now it won’t dupilicate?

HERE IS THE ERROR BELOW

--Installer Script

--Icons to use
set hotFolderIcon to (path to me)'s POSIX path & "Contents/Resources/Icons/hotFolder.icns"
set workFlowIcon to (path to me)'s POSIX path & "Contents/Resources/Icons/workFlow.icns"
set keywordIcon to (path to me)'s POSIX path & "Contents/Resources/Icons/keywords.icns"

--Script to use

(*set EAN to (path to me)'s POSIX path & "Contents/Resources/Scripts/1_EAN2SKU.scpt"
set sortedtoDestination to (path to me as string) & "Contents/Resources/Scripts/2_HotSorted2Destination.scpt"
set LayerSort to (path to me)'s POSIX path & "Contents/Resources/Scripts/3_SortByNumberOfLayers.scpt"
set Sorter2do to (path to me)'s POSIX path & "Contents/Resources/Scripts/4A_FileSorterHotFolder2Do.scpt"
set sortedDone to (path to me)'s POSIX path & "Contents/Resources/Scripts/4B_FileSorterHotFolderDone.scpt"
set LayerRatioandkeywords to (path to me)'s POSIX path & "Contents/Resources/Scripts/5_LabelFilesByRatioGroup.scpt"
*)
--Install Blank Folders

tell application "Finder"
	set Hotfolder to make folder at (path to desktop) with properties {name:"Hotfolder"}
	my setIcon((result as alias)'s POSIX path, hotFolderIcon)
	set desktop position of the Hotfolder to {2487, 150}
	set keywords to make folder at (path to desktop) with properties {name:"Keywords"}
	my setIcon((result as alias)'s POSIX path, keywordIcon)
	set desktop position of the Hotfolder to {2487, 250}
	
end tell

set heliconFocus to (path to me as text) & "Contents:Resources:Scripts:0_HeliconHotFolder.scpt" -- HFS path string
tell application "Finder"
	set WorkFlow to make folder at home with properties {name:"Workflow"} -- Finder folder specifier
	set thefolderactions to (make folder in WorkFlow with properties {name:"Folder Actions"}) -- Finder folder specifier
	duplicate file heliconFocus to thefolderactions -- file is needed to make a Finder file specifier
end tell

--Script placement






--ICON CREATOR
on setIcon(f, imagef)
	(*
        string f : POSIX path of target file or folder
        string imagef : POSIX path of image file
    *)
	set rb to "require 'osx/cocoa'
include OSX
raise ArgumentError, %Q[Usage: $0 <file> <image file>] unless ARGV.length == 2
file, imagef = ARGV
image = NSImage.alloc.initWithContentsOfFile(imagef)
NSWorkspace.sharedWorkspace.objc_send(
    :setIcon, image,
    :forFile, file,
    :options, 0)
"
	do shell script "/usr/bin/ruby -e " & rb's quoted form & " " & f's quoted form & " " & imagef's quoted form
end setIcon

Hello.

Is there more to this?

Are you having a folder action running in the same folder you are copying to? And what is the privileges of that folder?
Surmising you have tested that you can copy (duplicate a file to another folder.

Just wondering.

And you seem to know your way around with ruby, so why not perform the copying with a do shell script? At least to see if that works out, it is always good to try alternative paths when you struggle.

Less overhead involved.

The “Folder action” is only a folder name

I’m trying to make a script that installs the items and folders same always the same and, fingers crossed, always works.

Sadly no I don’t know my way round ruby, just been having help on the forums :slight_smile:

Well. I suggest you intersperse your statements with try catch clauses.

I see that the operation is named copy in the log statement, whereas it stands duplicate in your code.

It is odd behaviour, i’m at work at the moment and it runs without a problem here 10.6.9 I’ll try again when I get in on 10.8.2

Your ‘make’ commands are malformed, but seem to work. The ‘duplicate’ command is correct and should work. The likelihood is that there’s some problem with the file you’re trying to duplicate. I can’t guess what this might be, but things to check would include permissions and the file being in use.

The correct syntax for ‘make’ is ‘make new at ’, so:

tell application "Finder"
	set WorkFlow to (make new folder at home with properties {name:"Workflow"}) -- Finder folder specifier
	set thefolderactions to (make new folder at WorkFlow with properties {name:"Folder Actions"}) -- Finder folder specifier
	duplicate file heliconFocus to thefolderactions -- file is needed to make a Finder file specifier
end tell

Also, the Finder has its own term ‘desktop’ for the Desktop, so you don’t need ‘(path to desktop)’ in a Finder ‘tell’ statement:

tell application "Finder"
	set Hotfolder to (make new folder at desktop with properties {name:"Hotfolder"})
	my setIcon((Hotfolder as alias)'s POSIX path, hotFolderIcon)
	set desktop position of the Hotfolder to {2487, 150}
	set keywords to (make new folder at desktop with properties {name:"Keywords"})
	my setIcon((keywords as alias)'s POSIX path, keywordIcon)
	set desktop position of the Hotfolder to {2487, 250} -- You probably mean '. of keywords' here!
	
end tell