Scenario description
This side needs to go to a ftp regularly to download the data down and change their fields. The process is:
- Download from a place to get a file name called "202301081014XXXX.REQ" data format xml
- change the data of one of the fields of S001 which content is "1234" Change it to "abcd"
- If the change is completed, create a file with the same name and name it as "202301081014XXXX.REQ.OK" 4.Upload the two created data to another ftp path
Currently I have tried the action
- via Mac app script tools
- The operation of recording the screen is as follows
tell application "Finder"
activate
open document file "202301081014N1234.REQ" of folder "Downloads" of folder "blue2" of folder "Users" of startup disk using application file "BBEdit.app" of folder "Applications" of startup disk
end tell
tell application "BBEdit"
activate
open find window
find "<S001>1234</S001>" searching in text 1 of text document id 829 with selecting match
set characters 406 thru 428 of text document id 829 to "<S001>abcd</S001>"
select insertion point after characters 406 thru 428 of text document id 829
save text document id 829
end tell
Problems encountered
Because the names of the data are different, I have read the official documents but I don't know how to define the scope. And the <S001> field is in a different position, so I can't execute the recorded AppleScript.
find
command will return a record containing a reference to the character range of a match.sed
orawk
to fine/replace text elements quickly and efficiently.find
but it still have the document id that if i open anoother file want to use sripts that it can not work