Copying files from folder where the script is

Hi,

I want to write an applescript, that copies all files from a Folder called “Manual install” ot a folder called “~/Library/iTunes/iVisualize”

set sourceFolder to "Manual Install"
set destFolder to "~/Library/iTunes/iVisualize"

tell application "Finder"
	duplicate every file of folder sourceFolder to folder destFolder replacing yes
end tell

The duplicate line fails. I’m not sure wether that is because I just give the relative path or because the path is given by a string.

How does the script have to look like so that it does what I hoped to.

Thank you!

Greeting from Germany
Christoph Vogelbusch

Birdy27,

I believe you need more information in your folder paths. Something like:

set sourceFolder to "yourHardDriveName:userName:Users:Desktop:Manual Install:"

I used the Desktop just as an example. You have to have the complete path from your folder to the hard drive it is on. This would be the same for your destFolder variable. Note that when you declare a variable as a path to a folder that it must end with a colon (“:”). For a file path you leave off the colon. You will also have to use the words folder and file infront of your variables within a Finder tell block for the Finder to understand that it should be looking for a folder.

PreTech

“Manual Install” is in the current folder.
How can I get the full path name that the script is running in?
And how can I append the "Manual Install?

Greetings
Christoph

That means nothing to AppleScript or the Finder.

Let me make sure I understand. I’m thinking you have a file(s) on a disk image that you want to make available. You want to include an small application on this disk image that will copy the file to the right place. Is that close to being right?

That’s exactly it. I want to write a simple installer that should

  1. check for a certain file. Abort if it does not exist
  2. copy all files from a disk image’s folder to a local one in the home directory
  3. give out a message how to continue

Greetings
Christoph

I have edited one of my applescripts which I use to copy Disk image’s to my applications folder.

This one may give you some ideas.


tell application "Finder"
	set start_up to name of startup disk
	set nope to 1
	try
		if name of target of Finder window 1 is start_up then
			set nope to 2
		end if
		if ejectable of target of Finder window 1 is false then
			set nope to 3
		end if
		if local volume of target of Finder window 1 is false then
			set nope to 5
			
		end if
		if nope is equal to 1 then
			my _copy_Disk()
		else
			my _notdImage()
		end if
		
		
	on error
		my _notdImage()
		
	end try
end tell
on _notdImage()
	set error_message to "Front Finder window open is not a disk image"
	display dialog the error_message buttons {"Cancel"} default button 1
end _notdImage
on _copy_Disk()
	tell application "Finder"
		if class of target of Finder window 1 is disk then
			set VizFolder to path to library folder from user domain as string
			set viz to "iVisualize"
			set VizFolder to VizFolder & "iTunes:" as string
			set FRontWinName to target of Finder window 1
			set VizFolderTest to VizFolder & viz as string
			if (not (exists folder VizFolderTest)) then
				tell application "Finder" to make new folder at VizFolder with properties {name:viz}
			end if
			set VizFolder to VizFolder & viz as string
			duplicate every item of FRontWinName to VizFolder with replacing
			
		end if
	end tell
end _copy_Disk



Try something like this:

set ASTID to AppleScript's text item delimiters
set AppleScript's text item delimiters to {":"}
set folderInstall to text 1 thru text item -3 of (path to me as Unicode text)
set AppleScript's text item delimiters to ASTID

set folderInstall to quoted form of POSIX path of (folderInstall & ":Manual Install:")
set folderDestination to quoted form of POSIX path of ((path to library folder from user domain as Unicode text) & "iTunes:iVisualize:")

try
	do shell script "/bin/mkdir -p " & folderDestination & "; cd " & folderInstall & "; /bin/cp * " & folderDestination
	display dialog "Items copied successfully." buttons {"OK"} default button 1 with icon note
on error errorMsg number errorNum
	display dialog "Error (" & errorNum & "):" & return & return & errorMsg buttons "Cancel" default button 1 with icon caution
end try

.or this:

set folderInstall to path to me

tell application "Finder"
	launch
	set folderInstall to (((container of folderInstall) as Unicode text) & "Manual Install:") as alias
	
	
	set folderDestination to (path to library folder from user domain as Unicode text) & "iTunes:"
	try
		make new folder at result with properties {name:"iVisualize"}
		set folderDestination to result as alias
	on error errorMsg number errorNum
		if errorNum is not -48 then
			display dialog "Error (" & errorNum & "):" & return & return & errorMsg buttons "Cancel" default button 1 with icon caution
		else
			set folderDestination to (folderDestination & "iVisualize") as alias
		end if
	end try
	
	try
		duplicate (files of folderInstall) to folderDestination with replacing
	on error errorMsg number errorNum
		display dialog "Error (" & errorNum & "):" & return & return & errorMsg buttons "Cancel" default button 1 with icon caution
	end try
end tell

display dialog "Items copied successfully." buttons {"OK"} default button 1 with icon note

Just thought, is there not a installer maker with the developer tools.

Yes, and it is the recommended way of installing when the usual drag and drop way isn’t sufficient.

I just had a play with it, Not that hard to get your head around.

Birdy27, I suggest you install the Developer tools if you haven’t already.

You can find the PackageMaker.app
Here.
/Developer/Applications/Utilities/PackageMaker.app

Thanx you for all your hints about Applescript.
I will instantly try your example code.

The reason for not using Packagemaker are:

  1. Packagemaker does not allow installing into the users directory. (Means I would have to install in to tmp and then copy the files from a script, which does not make any sense for a packagsystem.)
  2. I want to create this not for me, but also for others who wish to create iVisualize Compositions.

Greetings
Christoph

I never though AppleScript would be easy to a freshman, but it really is not.
The reason I wanted to Apple Script is so that every visualization author can adapt the script to his need. I think only a minority will be able.

This kind of path representation is very strange to me, but thanks to your code I can handle it.

Despite that my script is working fine, thanks to you guys!

tell application "Finder"
	set libraryFolder to path to library folder as string
	set iViFolder to libraryFolder & "iTunes:iTunes Plug-ins:iVisualize.bundle:Contents:" as string
	set userLibraryFolder to path to library folder from user domain as string
	set userIViFolder to userLibraryFolder & "iTunes:iTunes Plug-ins:iVisualize.bundle:Contents:" as string
	if not (exists folder iViFolder) and not (exists folder userIViFolder) then
		display dialog "You need iVisualize to use this " & return & " Quartz Composition in iTunes!" buttons {"Cancel", "Open Webpage"} default button 2 with icon caution
		set the user_choice to the button returned of the result
		if user_choice is "Open Webpage" then
			open location "http://web.mac.com/vogelbusch/iWeb/Site/iVisualize.html"
		end if
	else
		my _do_copy()
	end if
end tell

on _do_copy()
	set userLibraryFolder to path to library folder from user domain as string
	set iTunesFolder to userLibraryFolder & "iTunes:" as string
	set iViQCFolder to iTunesFolder & "iVisualize:" as string
	tell application "Finder"
		if not (exists folder iViQCFolder) then
			make new folder at iTunesFolder with properties {name:"iVisualize"}
		end if
	end tell
	
	set currentVolume to text 1 thru text item -13 of (path to me as Unicode text)
	set sourceFolder to (currentVolume & ":Manual Install:")
	set destFolder to userLibraryFolder & "iTunes:iVisualize:" as string
	tell application "Finder"
		duplicate every file of folder sourceFolder to folder destFolder replacing yes
	end tell
	
	display dialog "The Quartz Composition has been copied. You can choose it now from the option panel of iVisualize in iTunes." buttons {"OK"}
end _do_copy

Greeting from Germany
Christoph Vogelbusch