Testing for file existence, what am I doing wrong

Hello, first off let me tell you what I am trying to accomplish.
We have around 50 Macs in our medical research labs that access a shared samba drive. The constant .ds_store placement bothers the windows users.

I know you can use the defaults utility to stop this (via apple’s site), but that only works for a single user profile. I need a solution that will work for any user that logs into the computer (anyone with an AD account can authenticate).

My solution was to create a log-in script that checks to see if the plist is in the ~/Library/Prefrences of the user before mounting the drive. If the file does not exist, it should copy the file, then restart the workstation.

I had this working fine in a bash script but the problem is I don’t know of a way to force a restart from the terminal without su access.

So I decided a applescript would be more fitting. The problem I run into is checking to see if the file exists in the users folder.


set posixPath to do shell script "cd ~/Library/Preferences;  pwd"
set ASpath to POSIX file posixPath --converts UNIX-->applescript

set itExists to (exists the file "com.apple.desktopservices.plist" in path, ASpath)

if itExists = true then
	tell application "Finder"
		mount volume "smb://cancer1/shared$"
	end tell
else
	do shell script "cp -p " & "/com.apple.desktopservices.plist" & " " & "~/Library/Preferences/"
	display dialog "Configuration complete" & return & "Computer must restart" & return & fileInfo buttons {"Restart"} default button 1
	tell application "finder"
	      restart
	end tell 
end if

Thats what i got so far, but it fails on the exists statement, claiming “Can’t make file “com.apple.desktopservices.plist” of path into type reference.”

This is my first applescript I have written so ANY suggestions would be greatly appreciated

Thanks, I hope I have described my situation with enough detail. (also if any knows how to reach the end result, no .ds_stores on a network drive, some other way feel free to let me know)

I haven’t used the posix paths before but I was wondering if the comma should be here as you have it.

Have you tried taking the comma out as such:

set itExists to (exists the file "com.apple.desktopservices.plist" in path ASpath)

Best suggestion I have. Good luck.

nope, it doesnt work.
In fact the reason i put that there is because if you take it out, you cannot compile, it complains Expected ", " but found identifier.

Im pulling my hair out on this one

Hi,

‘exists’ is a Finder or System Events command so you need to place it in a tell block.

tell app “System Events”
set v to exists SomeObjectReference
end tell

gl,

Hi,

You don’t really need to use ‘exists’. The following will error when coercing to ‘alias’ reference if the file doesn’t exist.

set pref_path to (path to preferences folder from user domain) as string
try
set plist_ref to (pref_path & “com.apple.desktopservices.plist”) as alias
on error – file wasn’t found
– do whatever
beep 2
end try

gl,