Mombu the Programming Forum sponsored links

Go Back   Mombu the Programming Forum > Programming > Applescript or Perl or other???
User Name
Password
REGISTER NOW! Mark Forums Read

sponsored links


Reply
 
1 1st May 06:05
jimt
External User
 
Posts: 1
Default Applescript or Perl or other???



As i havent done any coding in a long time (again!!)
will be writing an app/script that
1. takes a text file that is a list of files as input
1a. strips everything after the first delimiter leaving just the file
name
2. searches a designated folder of folders for those files
3. as locates files copies to a designated folder
4. tells osiris to send requested files to newsgroup

Dusting off my Perl i find this is an interesting challenge.
I know i could write this in C
would rather do in apple script

is this a reasonably doable?

BTW the step 4 i believe could be done with a folder action and then an
osiris script to send it out.
thanks
jimt
  Reply With Quote


  sponsored links


2 1st May 06:05
koncept
External User
 
Posts: 1
Default Applescript or Perl or other???



Hi Jim. Maybe this can get you started. The script expects the infoFile
to have posix paths ( /volumes/subdir/file.ext ). You could make this
faster by using a regex on the cat command via a pipe to strip out all
the paths leaving just the file names. I am sure that parsing it with
AppleScript's TID's will be slower than a sed pipe.

set infoFile to choose file with prompt "Where is the info file?"
set searchDir to choose folder "Where is the directory to search?"
set outputDir to choose folder "Where should I save any located files?"

(* read the file contents into a list *)
set myhandle to quoted form of POSIX path of infoFile

try
set fileInfo to do shell script "/bin/cat " & myhandle
set pathList to every paragraph of fileInfo
on error
beep (2)
display dialog "An error occurred" with icon stop
return false
end try

(* get file names *)
set OD to AppleScript's text item delimiters
set AppleScript's text item delimiters to "/"

if pathList ‚ {} then

tell application "Finder"
set checkNames to name of files of searchDir

repeat with aPath in pathList
(* isolate the file name from the path *)
set searchFile to last item of text items of aPath
set fileCheck to ¬
(items of searchDir whose name is searchFile)
if fileCheck ‚ {} then ¬
duplicate item 1 of fileCheck to outputDir with replacing
end repeat

end tell
else
beep (2)
display dialog "The info file contained no content!" with icon stop
end if

set AppleScript's text item delimiters to OD

--
Koncept <<
"Contrary to popular belief, the most dangerous animal is not the lion or
tiger or even the elephant. The most dangerous animal is a shark riding
on an elephant, just trampling and eating everything they see." - Jack Handey
  Reply With Quote
3 1st May 06:06
koncept
External User
 
Posts: 1
Default Applescript or Perl or other???


Oops. Replace these two lines with this:

set searchDir to choose folder with prompt ¬
"Where is the directory to search?"
set outputDir to choose folder with prompt¬
"Where should I save any located files?"

--
Koncept <<
"Contrary to popular belief, the most dangerous animal is not the lion or
tiger or even the elephant. The most dangerous animal is a shark riding
on an elephant, just trampling and eating everything they see." - Jack Handey
  Reply With Quote
4 1st May 06:06
jimt
External User
 
Posts: 1
Default Applescript or Perl or other???


I like it. will use the applescript approach.
thanks
jimt
  Reply With Quote
Reply


Thread Tools
Display Modes




Copyright © 2006 SmartyDevil.com - Dies Mies Jeschet Boenedoesef Douvema Enitemaus -
666