How to set internal source location for installer?

I am trying to create a very simple basic installer for a single text-like file to be installed into a specific user-preferences folder. This installer will be used by multiple persons on their computers if needed.

If I create an applescript installer with the item to be installed inside the Contents folder, I cannot seem to find an appropriate command to refer to this source location.

I have tried both applescript and unix commands. But I am too simple minded to find how the source location should be referred to in either of those approaches. The unix cp command’s source location I have tried over and over.

I’ve been googling for a week on this topic without finding an answer that actually works.

Any suggestions for either applescript or unix, I would be greatly appreciative.

I have had partial success using a couple of techniques but on second runs, get errors.

The issue with an installer is the installer might be sitting anywhere on a person’s computer, such as their documents folder or an alternative HDD or a disk image or CD or even a network.

When you save a script as application you’ll have a Resources folder in the Contents folder. You can get at any item in that folder with this command:

set thisSource to path to resource "your resource's name"

Thank you for your reply.

Can you or anybody tell me what is wrong with this script:

set thisSource to path to resource "gnutella.net"

set theDestinationFolder to (path to preferences folder from user domain)

tell application "Finder"
	
	move "gnutella.net" to theDestinationFolder with replacing
	
	do shell script "cp ~/Library/preferences/gnutella.net ~/Library/preferences/limewire"
	
end tell

Error: Can’t make “gnutella.net” into type item.

I cannot even seem to get the script to work let alone to the final destination which is why the dual steps. :frowning:
I had tried
(path to preferences folder from user domain) & “limewire:gnutella.net” as text
but that did not work.

Here’s a commented copy of your script, and my edited version:

set thisSource to path to resource "gnutella.net"
(* from here on use 'thisSource' to refer to this item: it is a full path *)

set theDestinationFolder to (path to preferences folder from user domain)

tell application "Finder"
	move "gnutella.net" to theDestinationFolder with replacing
	(* don't use 'move', it will make the installer useless afterwards,
		as the installable is no longer there. You want 'duplicate'	
	*)
	do shell script "cp ~/Library/preferences/gnutella.net ~/Library/preferences/limewire"
	(* don't put command in a tell block when it is not meant for that application.
		Anyway, why the two-step install? When you know the target folder you can put your file
		 in there in one step 
	*)
end tell
--
-- my edited version
--
set thisSource to path to resource "gnutella.net"

-- 'theDestinationFolder' is an alias
set theDestinationFolder to (path to preferences folder from user domain)

-- make path to known destination folder
set theDestinationFolder to ((theDestinationFolder as text) & "limewire:") as alias
-- maybe 'limewire' should start with a capital. Note the colon at the end!
-- this command will fail when the target folder does not exist

-- nothing disappears from the installer, so it remains usable
tell application "Finder" to duplicate thisSource to theDestinationFolder with replacing

I can see how the move command would stop the process working more than once. :smiley:

Runs very well thank you very much! Although the folder has two capitals, as in LimeWire, the file finds its way there. But if that was pure luck on my system, then I guess I should change it to the 2 capitals?

I have another small addition to add.

The gnutella file is used by several gnutella programs and a large number of people. The most popular software has two versions still used, v.4 and v.5. This last version 5 (and L.P.E.) has a bit of a dilemma. As the program opens, if it detects the gnutella.net file is 30+ days old it will immediately delete the file. Even though the data is usually good for up to 3-4 months after last use.

I need to be able to change the gnutella.net file’s modification date to today’s date (date of installation.) I’ve looked around at Unix and Applescript concepts for achieving this. Some are complex. And it seems they are limited to OSX 10.4 or even 10.5 or later. And/or require the person to have applescript additions or developer kit on their machine.
Do you know of any answer to modify the file’s date which would be compatible with the earliest possible OSX versions?

This might sound silly, but the simplest solution I can think of is to open the gnutella.net file with TextEdit and save (without making changes, but it does change the modification date if done manually.) This seems to work for Snow Leopard which I use, but I am not sure TextEdit/system finder works same way in the earlier OSX’s. This simple approach does stop the program I mentioned from deleting the file. How can I add this to the last script you generously suggested? I am obviously not very clever with scripting. :smiley:

A part of the code I suspect would begin like …

tell application "Finder" to set appName to name of application file id "ttxt" as string
-- the string approach would be compatible with earlier OSX's afaik
set filepath to (path to preferences folder from user domain)
set filepath to ((filepath as text) & "limewire:gnutella.net") as alias
tell application appName to open filepath
tell application appName to close filepath with saving
end

OR

tell application "Finder" to set appName to name of application file id "ttxt" as string
set filepath to (path to preferences folder from user domain)
set filepath to ((filepath as text) & "limewire:gnutella.net") as alias
set thefile to filepath
tell application appName to open thefile
tell application appName to close thefile with saving
end

But although this opens the document, it does not save or close it. Also it would be preferable for it to do its actions in the background rather than visibly. I’ve obviously mucked up the file reference and actions.
Also i guess to be sure the document is modified, perhaps the text could be changed color before saving. Since it is a plain text document it will not actually change it but will change modification date. Or instead perhaps add a space on last line which is empty anyway. :smiley: Or even add a preset extra line of numbers. Or is this approach to changing mod. date a silly idea?

Although (most of) the OS seems to be case-agnostic (for now) it is better to err on the safe side.

“30+ days old”: does that mean created/modified/last used more than 30 days ago?
touch -m “path/to/file” will change the modification date to “now”.
But I believe you should try to figure out why v.5 deletes that “old” file.

Works like a charm. I am so very grateful. And I know many other people will be too. :smiley:

Modify date only applicable. Very simple fix.

My mistake, I must have misread that the touch command was only compatible with OSX 10.4/5 or higher. But I’ve since found a OSX forum post about it from 2004.

Last version of V.4 & all v.5 versions have bootstrap abilities. The company had bootstrap servers which helped speed up connection. Once the program is connected to at least one host, it has the ability to search for more hosts to connect to. Upon shutting down, LW writes its survey & connection results of available hosts to the gnutella.net file. ie: adding new hosts, marking success or unsuccessful connection to hosts but online or not found. Once failed too many times hosts are usually replaced.

The idea of deleting the gnutella.net file after 30 days was to make sure users had up-to-date connection data to help speed up total connection (to 3 or 5 hosts as a leaf.) The bootstrap server acted as an insurance of connection. Once this was shutdown in 2010, many LW users had problems connecting. This also affected earlier LW4 versions because less peers online to connect to that were in their gnutella.net file list.

I can only think that the overall answer for Mac LW v.5 users would be to have an applescript that is launched same time as LW v.5 is, which modifies the date of the gnutella.net file.
(A year ago a fellow forum member created a fix for windows to stop the deletion of the file, but we now think it does not work properly or may even have ill effects on stopping connections. I intend to test it as much as I can. I’d need to ask her what it does.)