Hi,
I’m trying to come up with a script that will find a string in everyfile in a specific folder and replace that string.
I have tried and tested the one below and this works but only if a file is dropped onto the application.
Ideally I’d like a simple command line… but I can’t find one that works… help…
he’s my attempt so far…
on open (aliasList)
set textToFind to “%%EndComments”
set textReplacement to "%
%HDJobstream V 2.7.3; JobID = 4
%
%%EndComments
%% OPC: HQS7CheckerNeg150
%
% PSBeforeOPC
%
currentfile 1 (%LHCOPCEnd) /SubFileDecode filter flushfile
%LHCOPCBegin: 1796
%!PS-Adobe-2.0
%%Copyright: (C) 1998 Heidelberger Druckmaschinen AG
%%BeginPrologLOC LinoOutputControl
statusdict/product known { statusdict/product get exec }{ ( ) }ifelse
(Linotype) eq{
{(Lino/LOC/defs) status } stopped not { {clear (Lino/LOC/defs) run}if } if
userdict /loc_dict known {
% define_token_if_unknown
/dtiu {
dup loc_dict exch known not { loc_dict exch { pop } put }{ pop } ifelse
} def
loc_dict begin
/loc_version dtiu
/loc_name dtiu
/loc_rip dtiu
/loc_recorder dtiu
/loc_negativemode dtiu
/loc_mirrormode dtiu
/loc_dotshape dtiu
/loc_screenfrequency dtiu
/loc_screening dtiu
/loc_interpreter_res dtiu
/loc_screenmode dtiu
/loc_substituteangles dtiu
/loc_slugline dtiu
/loc_slugline_usertext dtiu
/loc_alignmentmarks dtiu
/loc_app dtiu
/loc_resolution dtiu
/loc_punch dtiu
/loc_processcalib dtiu
/loc_cnf_punch dtiu
/loc_cnf_screen dtiu
/loc_activate dtiu
/loc_negativesuppl dtiu
/loc_delta_res dtiu
/loc_material dtiu
/loc_colorseparation dtiu
/loc_ds dtiu
/loc_gravure dtiu
/loc_printer dtiu
/loc_cropmarks dtiu
/loc_jobscale dtiu
/loc_matcut dtiu
/loc_colorangles dtiu
/loc_color_temp dtiu
/loc_source dtiu
%%BeginSetupLOC
(1.2) loc_version
(MAC-OPC) loc_source
(headers:PSHeaders:DavesTest) loc_name
(Herkules/DeltaRIP) loc_recorder
(DeltaRIP) loc_rip
(1) loc_ds
(1) loc_gravure
(0 ) loc_printer
(1693) loc_resolution
(on) loc_negativemode
(HQS7.5) loc_screening
(quality) loc_interpreter_res
(round) loc_dotshape
(133) loc_screenfrequency
(150) loc_colorangles
%
%%EndSetupLOC
%%BeginEpilogLOC
% now activate the above
% routine - dtiu - in header_prolog needs a dummy string
(dummy) loc_activate
%%EndEpilogLOC
end % loc_dict
} if % loc_dict known
} if % Linotype
%%EndPrologLOC
%LHCOPCEnd
%%BeginDefaults"
repeat with i from 1 to aliasList's length
set aliasFile to aliasList's item i
-- Filter out folders:
--
if ((aliasFile as string)'s character -1 is not ":") then
set fileRef to open for access aliasFile with write permission
try
set fileContents to read fileRef
-- note: case-sensitive
--
set fileContents to my ReplaceText(fileContents, textToFind, textReplacement)
-- clear the file's contents
--
set eof fileRef to 0
write fileContents to fileRef
close access fileRef
on error e number n from f to t partial result p
try
close access fileRef
end try
error e number n from f to t partial result p
end try
end if
end repeat
end open
on ReplaceText(s, f, r)
set astids to AppleScript’s text item delimiters
try
set AppleScript’s text item delimiters to f
set s to s’s text items
set AppleScript’s text item delimiters to r
set s to s as string
set AppleScript’s text item delimiters to astids
return s
on error e number n from f to t partial result p
set AppleScript’s text item delimiters to astids
error e number n from f to t partial result p
end try
end ReplaceText