Go Back   The macosxhints Forums > OS X Help Requests > AppleScript



Reply
 
Thread Tools Rate Thread Display Modes
Old 02-28-2012, 07:18 PM   #1
Going Postal
Prospect
 
Join Date: Feb 2006
Posts: 14
File finder script for networked computers

Ive tried to do this script and failed. Hopefully someone can help me.

I need to:

1. do a search across 6 networked computers to find a file.(Needs to ask for a file name)
2. If the computers arent mounted the need to be mounted
3. Once that file is found i need a window showing what the computer name and folder it is located on, and all the info of the file itself.

any ideas?

I am using osx10.6.8
Going Postal is offline   Reply With Quote
Old 02-28-2012, 07:36 PM   #2
tw
Hall of Famer
 
Join Date: Apr 2007
Posts: 4,262
are the computers normally mounted on the searching computer? If so, this is easy to do in applescript; if not, you'll either have to mount them or ssh into each to do the search.
__________________
Philosophy is a battle against the bewitchment of our intelligence by means of language. -LW-
tw is offline   Reply With Quote
Old 02-28-2012, 08:02 PM   #3
Going Postal
Prospect
 
Join Date: Feb 2006
Posts: 14
They are already mounted on the searching computer. Im new at this so i really struggled getting it to work

thanks
Going Postal is offline   Reply With Quote
Old 02-28-2012, 08:38 PM   #4
tw
Hall of Famer
 
Join Date: Apr 2007
Posts: 4,262
well, start with this, which does the search (assuming that everything is mounted at /volumes, as is typical)

Code:
tell application "Finder"
	set volumeList to name of every disk
end tell

display dialog "What file are you looking for?" default answer ""
set fileToFind to text returned of the result

repeat with thisVolume in volumeList
	set cmd to "mdfind \"kMDItemFSName = " & fileToFind & "\" -onlyin '/volumes/" & thisVolume & "'"
	set foundFiles to (do shell script cmd)
	if foundFiles ≠ "" then
		display alert "Files Found" message foundFiles
		exit repeat
	end if
end repeat
As for mounting the disks, I need to know more about how they are supposed to mount. are they network servers? attached drives? If they are not mounted when the script is run, then the script needs to know the volume name and where to look for it in order to mount it.
__________________
Philosophy is a battle against the bewitchment of our intelligence by means of language. -LW-
tw is offline   Reply With Quote
Old 02-28-2012, 09:03 PM   #5
Going Postal
Prospect
 
Join Date: Feb 2006
Posts: 14
thank you for that, it works great. The disk are the network shares from the other computers, to mount a disk i have to use the example string: afp://Copper._afpovertcp._tcp.local. This mounts all the shared folders on that computer.
Going Postal is offline   Reply With Quote
Old 02-29-2012, 04:46 AM   #6
tw
Hall of Famer
 
Join Date: Apr 2007
Posts: 4,262
well, mounting an afp share should be straight-forward:

Code:
mount volume "afp://Copper._afpovertcp._tcp.local"
You could simply run that every time you run the script - I don't think it will hurt anything if the volumes are already mounted, though it may cause a script slowdown. (it's part of the Standard Additions osax, so don't put it inside a Finder tell block - use it at script level). If you want to check whether the volumes are mounted first, you can loop through the disk names and do something like the following:

Code:
tell application "Finder"
	set thisDiskIsMounted to exists disk disk_name
end tell
if not thisDiskIsMounted then
	mount volume disk_name on server "afp://Copper._afpovertcp._tcp.local"
end if
you can also get more information than just the mount path, but you need to say what information you want. that can range from simple information available from the Finder or System Events to esoteric low-level stuff pulled from unix.
__________________
Philosophy is a battle against the bewitchment of our intelligence by means of language. -LW-
tw is offline   Reply With Quote
Old 02-29-2012, 05:00 PM   #7
Going Postal
Prospect
 
Join Date: Feb 2006
Posts: 14
Thank you again for your help. ive set it up like this:

try
mount volume "afp://Copper._afpovertcp._tcp.local"
mount volume "afp://Zinc._afpovertcp._tcp.local"
mount volume "afp://Titanium._afpovertcp._tcp.local"
mount volume "afp://Lead._afpovertcp._tcp.local"
mount volume "afp://Thorium._afpovertcp._tcp.local"
mount volume "afp://Lithium._afpovertcp._tcp.local"

end try

set searchTerm to text returned of (display dialog "Enter search term" default answer "")

set theSearch to do shell script "find -f /Volumes/ | grep " & quoted form of searchTerm

if theSearch ≠ "" then
display alert "Files Found" message theSearch

end if
if theSearch = "" then
display alert "Files Not Found" message theSearch

end if

The search works, however when it comes to a drive that is local(mine is lead) it comes up with this message:

Connection Failed
The server "Lead" is available on your computer.
Access the volumes and files locally.

When i click ok it brings up the enter search term window without mounting the drives located after my drive. Is there a way to have this script ignore the local drives? I need to be able to use this script on all the computers in the group so i cant write it just for mine, otherwise i would just delete mounting my drive.

Thank you
Going Postal is offline   Reply With Quote
Reply

Tags
applescript, file search, networked

Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump



All times are GMT -5. The time now is 02:29 AM.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2014, vBulletin Solutions, Inc.
Site design © IDG Consumer & SMB; individuals retain copyright of their postings
but consent to the possible use of their material in other areas of IDG Consumer & SMB.