How can I write a Boolean expression for an if/then statement that detects whether or not a file whose filename begins with “TNV176” exists on the desktop? It seems there are no wildcard characters in applescript such as “*”.
tell application “finder”
if file “TNV176**.CLM” of desktop exists then
–do stuff here
end if
end tell
tell application "Finder" to set desktop_list to name of every file of desktop
repeat with this_item in desktop_list
if this_item begins with "TNV176" then
--do stuff here
end if
end repeat
Thank you blend3. Your script worked perfectly. Bruce, I didn’t try your scripts just because if the file exiswted, I would execute the statements else end the script. See below…
Doug
tell application "Finder" to set desktop_list to name of every file of desktop
global this_item
repeat with this_item in desktop_list
if this_item begins with "TNV176" then
tell application "BBEdit"
activate
set filename to this_item
set filepath to "PowerBook G4 HD:Users:amcsurgeons:Desktop:" & filename
open file {filepath} with LF translation
zap gremlins text 1 of text window 1 zap action delete_gremlin with filter linefeeds, non ASCII characters and controls
save window 1
select text 1 of text window 1
copy selection
set documentText to (the clipboard)
set AppleScript's text item delimiters to "SE*"
copy text item 1 of documentText to textChunk1
copy (text items 2 thru end of documentText) as text to textChunk2
set lineNumber to (length of (paragraphs of textChunk1)) - 2
set AppleScript's text item delimiters to "*"
set textChunk2 to (text items 2 thru end of textChunk2) as text
set AppleScript's text item delimiters to ""
set newText to textChunk1 & "SE*" & lineNumber & "*" & textChunk2
replace text 1 of window 1 using newText
save window 1
close text window 1
quit
end tell
end if
end repeat