Reference a file created in a script

I am trying to make a script that will be able to create a file with the current user’s name (logout-‘username’). the problem is i can’t figure out how to reference the file later in my script…

set username to system attribute “USER”
do shell script “touch /private/tmp/logout-” & username

how do you reference a file when you have no idea what it’s called?

-thx
dave

The best way would be to set a variable using the path to the file. Since you already know where the file is being created and you have the user name in a variable, you could use:

set theFile to (“Macintosh HD:private:tmp:logout-” & username) as alias

Hope this helps.

That sort of helps, but the problem with it is you can’t set an alias to something that doesn’t already exist. The file that I am trying to create will come and go, it’s meant to be a placeholder, so based the nonexistence/existence of that file the script will know what to do.

-ds

Then how about this:


set theFile to "Macintosh HD:private:tmp:logout-" & username as string
if exists file theFile then
--do something
else
--don't do something
end if

Here, the variable is just holding a string of text with the path to where the file should be. Then when you want to see if it’s been created, you’re just checking to see if a file with that name at that location exists. Hope this helps.

Thanks for your input so far, I am hoping the answer is within reach!
look at this simple script for me, i must be missing something. The script is suppsed to create a file and delete it. It always deletes the file but it doesn’t think it did!


set username to system attribute "USER"
set t to "touch /private/tse/logout-" & username
set r to "rm -f /private/tse/logout-" & username
set theFile to "MacintoshHD:private:tse:logout-" & username as string

try
	do shell script r --just to make sure
end try

do shell script t --create the file

delay 2

tell application "Finder"
	if exists file theFile then
		display dialog "it's there"
	else
		display dialog "it's not there."
	end if
end tell

try
	do shell script r --delete the file (it works)
end try

delay 2

tell application "Finder"
	if exists file theFile then
		display dialog "it's still there"
	else
		display dialog "it's not there."
	end if
end tell

it always says it’s still there! what am i doing wrong??