Hi Peter,
the first part of your request I understand. I saved plain text file from your example and used the code below to get a list containing three entries:
set thefile to choose file
set textToBeCleaned to read thefile
set master_list to {}
repeat with i from 1 to count of paragraphs of textToBeCleaned
set oldDels to AppleScript's text item delimiters
set AppleScript's text item delimiters to ";"
set theText to text item 2 of paragraph i of textToBeCleaned
if theText is not in master_list then copy theText to end of master_list
set AppleScript's text item delimiters to oldDels
end repeat
choose from list master_list
What I’m unsure of is are you intending on duplicating the same image 10209022 times??? and do you need the text file or can this all be incorporated into one script that cleans the text, duplicates and renames the file?
Thanks,
Nik
Iwant to use the cleaned text file as an input for renaming a masterfile named 00000000.eps
Let’s say we have a text file with:
12345678
22345678
and so on…
Create duplicates from 00000000.eps:
12345678.eps
22345678.eps
and so on…
Hi Peter,
The code below should do all you’re asking without creating a text file but if you would prefer to still have on then it’s not a problem to create one. The renamed files will be moved into the folder where the master eps resides.
Hope this helps,
Thanks,
Nik
set thefile to choose file with prompt "Please choose text file"
set file_to_duplicate to choose file with prompt "Please select master EPS file to duplicate"
set rename_temp to path to desktop
set textToBeCleaned to read thefile
set master_list to {}
repeat with i from 1 to count of paragraphs of textToBeCleaned
set oldDels to AppleScript's text item delimiters
set AppleScript's text item delimiters to ";"
set theText to text item 2 of paragraph i of textToBeCleaned
if theText is not in master_list then copy theText to end of master_list
set AppleScript's text item delimiters to oldDels
end repeat
tell application "Finder"
set master_name to name of file_to_duplicate
set the_Container to the container of file_to_duplicate
repeat with this_name in master_list
duplicate file_to_duplicate to rename_temp
set name of ((rename_temp as string) & master_name as alias) to this_name & ".eps"
move ((rename_temp as string) & this_name & ".eps" as alias) to the_Container
end repeat
end tell
only paragraphs ending with ;Nieuw artikel;; should be used
example:
Chaise Tygo;10301306;10;1030;129;;noir/chrome;;France;1;Nieuw artikel;; - use yes
Pout Supercord;10209024;35;3520;24.99;;noir;;France;5;Active;; - use no
I could use something like this:
set oldDels to AppleScript's text item delimiters
set AppleScript's text item delimiters to ";"
set theFilter to text item 9 of paragraph i of textToBeCleaned
set theText to text item 2 of paragraph i of textToBeCleaned
if theText is not in master_list and theFilter contains "Nieuw artikel" then copy theText to end of master_list
But in this case the ;; have to be replaced by ; - perhaps you know how, or is there another way
The original textfile always ends with an emty line - this has to be removed otherwise I get an error
Is it possible to have the textfile opened when starting the script - it’s always in the same folder, the modification date is the current date - jda_to_telescope_2009-05-07_09-00-01.txt
Hi Peter,
Please give the code below a try with regard to points 1 and 2:
set thefile to choose file with prompt "Please choose text file"
set file_to_duplicate to choose file with prompt "Please select master EPS file to duplicate"
set rename_temp to path to desktop
set textToBeCleaned to read thefile
set master_list to {}
repeat with i from 1 to ((count of paragraphs of textToBeCleaned) - 1) --> ignore blank paragraph
if paragraph i of textToBeCleaned contains "Nieuw artikel" then
set oldDels to AppleScript's text item delimiters
set AppleScript's text item delimiters to ";"
set theText to text item 2 of paragraph i of textToBeCleaned
if theText is not in master_list then copy theText to end of master_list
set AppleScript's text item delimiters to oldDels
end if
end repeat
tell application "Finder"
set master_name to name of file_to_duplicate
set the_container to the container of file_to_duplicate
repeat with this_name in master_list
duplicate file_to_duplicate to rename_temp
set name of ((rename_temp as string) & master_name as alias) to this_name & ".eps"
move ((rename_temp as string) & this_name & ".eps" as alias) to the_container
end repeat
end tell
It’s not a problem to open the text file can you a post the path to the folder where the text file resides, and can I assume that “jda_to_telescope_” is a static name but date part of the filename changes?
Thanks,
Nik
set thefile to choose file with prompt "Please choose text file"
set file_to_duplicate to choose file with prompt "Please select master EPS file to duplicate"
set rename_temp to path to desktop
set textToBeCleaned to read thefile
set master_list to {}
repeat with i from 1 to count of paragraphs of textToBeCleaned
set oldDels to AppleScript's text item delimiters
set AppleScript's text item delimiters to ";"
if paragraph i of textToBeCleaned contains ";" then
set theText to text item 2 of paragraph i of textToBeCleaned
if theText is not in master_list and paragraph i of textToBeCleaned contains "Nieuw artikel" then copy theText to end of master_list
set AppleScript's text item delimiters to oldDels
end if
end repeat
tell application "Finder"
set master_name to name of file_to_duplicate
set the_Container to the container of file_to_duplicate
repeat with this_name in master_list
duplicate file_to_duplicate to rename_temp
set name of ((rename_temp as string) & master_name as alias) to this_name & ".eps"
move ((rename_temp as string) & this_name & ".eps" as alias) to the_Container
end repeat
end tell
I tried both solutions and found a problem:
Using a small text file, let’s say 100 lines works okay
Using a learge text file, 1000 lines does not work - all the numbers are being processed
if paragraph i of textToBeCleaned contains "Nieuw artikel" then
or
if theText is not in master_list and paragraph i of textToBeCleaned ends with ";Nieuw artikel;;" then copy theText to end of master_list
Do not work.
A buffer problem?
The path is : Volumes:d$:Inetpub:ftproot:record_info_exchange:Archive_LB_to_Jonroo:jda_to_telescope_2009-05-07_09-00-01.txt
jda_to_telescope_ is fixed the rest is date/time
Hi Peter,
not sure why the code I supplied is not working but can you run a test for me? run the code below on your large text file. Does the list only contain the entries with “Nieuw artikel” in it?
Thanks,
Nik
set thefile to choose file with prompt "Please choose text file"
set file_to_duplicate to choose file with prompt "Please select master EPS file to duplicate"
set rename_temp to path to desktop
set textToBeCleaned to read thefile
set master_list to {}
repeat with i from 1 to ((count of paragraphs of textToBeCleaned) - 1) --> ignore blank paragraph
if paragraph i of textToBeCleaned contains "Nieuw artikel" then
copy paragraph i of textToBeCleaned to end of master_list
(*set oldDels to AppleScript's text item delimiters
set AppleScript's text item delimiters to ";"
set theText to text item 2 of paragraph i of textToBeCleaned
if theText is not in master_list then copy theText to end of master_list
set AppleScript's text item delimiters to oldDels*)
end if
end repeat
choose from list master_list
(*tell application "Finder"
set master_name to name of file_to_duplicate
set the_container to the container of file_to_duplicate
repeat with this_name in master_list
duplicate file_to_duplicate to rename_temp
set name of ((rename_temp as string) & master_name as alias) to this_name & ".eps"
move ((rename_temp as string) & this_name & ".eps" as alias) to the_container
end repeat
end tell*)
OK, can you give this one a try! All it’s doing is making a list of file that contain “Nieuw artikel” and then using that list to create a list of files to process.
Thanks,
Nik
set thefile to choose file with prompt "Please choose text file"
set file_to_duplicate to choose file with prompt "Please select master EPS file to duplicate"
set rename_temp to path to desktop
set textToBeCleaned to read thefile
set master_list to {}
repeat with i from 1 to ((count of paragraphs of textToBeCleaned) - 1) --> ignore blank paragraph
if paragraph i of textToBeCleaned contains "Nieuw artikel" then
copy paragraph i of textToBeCleaned to end of master_list
end if
end repeat
set new_master_list to {}
repeat with this_master_item in master_list
set oldDels to AppleScript's text item delimiters
set AppleScript's text item delimiters to ";"
set theText to text item 2 of this_master_item
if theText is not in new_master_list then copy theText to end of new_master_list
set AppleScript's text item delimiters to oldDels
end repeat
tell application "Finder"
set master_name to name of file_to_duplicate
set the_container to the container of file_to_duplicate
repeat with this_name in new_master_list
duplicate file_to_duplicate to rename_temp
set name of ((rename_temp as string) & master_name as alias) to this_name & ".eps"
move ((rename_temp as string) & this_name & ".eps" as alias) to the_container
end repeat
end tell
Can you help me with the part of auto selecting the text file.
the previous path was incorrect, it should be:
Volumes:d$:Inetpub:ftproot:record_info_exchange:log:jda_to_telescope_2009-05-07_09-00-01.txt
The script must be triggered by:
the creation date = the current date or from the date string in the file 2009-05-07 and an additional filter 09 (time)
Hi Peter,
sorry I’m still unclear on the path and filename of the text file. What is the name of the volume you have mounted on your desktop?
Is there likely to be more than one file in the directory that begins with “jda_to_telescope” and ends with “.txt”?
Thanks,
Nik
Volume on Desktop= d$
Path to Folder= d$:Inetpub:ftproot:record_info_exchange:log:
The log Folder contains many files starting with “jda_to_telescope” and also “telescope_to_convacpr”
The last one must be ignored
The one that I need is the jda_to_telescope with the current date string (creation date = current date)
example:
jda_to_telescope_2009-05-07_09-00-01.txt
Filter on creation date > yesterday & filename contains “09” ?
Filter on creation date = current date & filename contains “09” ?
Hi Peter,
can you give this a try? hopefully it will open a txt file whose name begins with “jda_to_telescope” that has the latest creation date!!
Thanks,
Nik
set source_folder to "d$:Inetpub:ftproot:record_info_exchange:log:"
tell application "Finder"
set file_list to every file of source_folder whose name begins with "jda_to_telescope" and name ends with ".txt"
set SortedFiles to sort file_list by creation date --> sort the list of files with the same name by creation date
open item 1 of SortedFiles
end tell
tell application "Finder"
set source_folder to "d$:Inetpub:ftproot:record_info_exchange:log:" as alias
set file_list to every file of source_folder whose name begins with "jda_to_telescope" and name contains "_09"
set SortedFiles to sort file_list by creation date --> sort the list of files with the same name by creation date
open item 1 of SortedFiles
end tell