Getting the path

Hi:

I’ve just written my first script. I call it from a REALBasic app that I’ve written.

tell application "Finder"
	duplicate file "Budget.rsd" of folder "REALBasic Projects 2009" of folder "Documents" of home
end tell

It works just fine on my machine. But this app will be run by a few other people on other machines. What I was wondering was how to write the script so that it will find the path to Budget.rsd on these other machines because the app won’t know where the file resides.

Thanks so much.


Martin
Signal Mountain, TN

This should do it. But I’m also not good in applescript, so the script might just not work. But if it works, I recommand you to save it as an application, and not as a script, if you know what I mean. Because every time you recompile the script, the variable TheBudgetFile is set to missing value. And in an application you can’t recompile something.

Script

property TheBudgetFile : missing value

if TheBudgetFile is missing value then set TheBudgetFile to (choose file without invisables)
tell application "Finder" to if not (exists TheBudgetFile) then set TheBudgetFile to (choose file without invisables)

tell application "Finder"
	duplicate file TheBudgetFile to (choose folder) -- insert where you want to copy the file to
end tell

hope it works,
ief2

PS.: I’m sorry for my English. I know I sometimes make some rubbish sentences, but I ask you to forgive me. I’m only 14 years old and I come from Belgium, so I speak dutch. If you don’t understand me, don’t hesitate to give a reply on that.

Hi,

assuming the file is located in the home folder of the current user
the most effective way to search it is the shell command find


set homeFolder to POSIX path of (path to home folder)
set budgetPath to do shell script "/usr/bin/find " & quoted form of homeFolder & " -name Budget.rsd"
set budgetFile to missing value
if budgetPath is not "" then
	set budgetFile to POSIX file (paragraph 1 of budgetPath) as alias
end if

or Spotlight, if the volume is indexed by Spotlight


set homeFolder to POSIX path of (path to home folder)
set budgetPath to do shell script "/usr/bin/mdfind -onlyin " & quoted form of homeFolder & " 'kMDItemFSName = \"Budget.rsd\"'"
set budgetFile to missing value
if budgetPath is not "" then
	set budgetFile to POSIX file (paragraph 1 of budgetPath) as alias
end if

The Spotlight version is probably faster, but anyway, both methods can take a long time depending on the size and the amount of files of the homefolder

ief2 and Stefan, thank you both so much for these responses. I’m sure I’ll be able to work the problem out now.

Martin