clean up text file and use for rename image

Can someone help me with this:

  • I have a text file that needs to be cleaned up either with textedit or textwrangler

example:

Poef Army;10209022;35;3520;24.99;;donker groen;;The Netherlands;5;Active;;
Poef Army;10209022;35;3520;26.99;;donker groen;;Flanders;5;Active;;
Pouf Army;10209022;35;3520;26.99;;vert foncÈ;;Walloon;5;Active;;
Pouf Army;10209022;35;3520;26.99;;vert foncÈ;;France;5;Active;;
Poef Lucy;10209023;35;3520;24.99;;roze;;The Netherlands;5;Active;;
Poef Lucy;10209023;35;3520;26.99;;roze;;Flanders;5;Active;;
Pouf Lucy;10209023;35;3520;26.99;;rose;;Walloon;5;Active;;
Pouf Lucy;10209023;35;3520;26.99;;rose;;France;5;Active;;
Poef Supercord;10209024;35;3520;21.99;;zwart;;The Netherlands;5;Active;;
Poef Supercord;10209024;35;3520;24.99;;zwart;;Flanders;5;Active;;
Pout Supercord;10209024;35;3520;24.99;;noir;;Walloon;5;Active;;
Pout Supercord;10209024;35;3520;24.99;;noir;;France;5;Active;;

What I want is only the number between the first ; and the second ; and remove the duplicates and save the file to my desktop.

  • Use this text file to create duplicates from an existing image (always in the same folder) and rename them - example: 00000000.eps > 10209022.eps

Any help is greatly appreciated !

–Peter–

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

Thanks for the input,

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…

Hope this makes things a bit more clear.

–Peter–

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

Hé Blend3, this is great!

I need two additions though

  1. 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

  1. 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

Thanks in advance,
Peter

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

Thanks,

This is what I came up with:

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*)

Hi,

All the lins contain only “Nieuw artikel”

–Peter–

Hi,
Does that mean that this is the correct list of files to be processed?
Thanks,
Nik

yep

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

Hi,

Works just fine !!

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)

Many thanks!

–Peter–

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

Examples:
jda_to_telescope_2009-05-07_13-00-01.txt
jda_to_telescope_2009-05-07_11-00-01.txt
jda_to_telescope_2009-05-07_09-00-01.txt
jda_to_telescope_2009-05-06_19-00-00.txt
jda_to_telescope_2009-05-06_17-00-00.txt
jda_to_telescope_2009-05-06_15-00-00.txt
jda_to_telescope_2009-05-06_13-00-00.txt
jda_to_telescope_2009-05-06_11-00-00.txt
telescope_to_convacpr_2009-05-06_09-09-55.txt
telescope_to_convacop_2009-05-06_09-09-55.txt
jda_to_telescope_2009-05-06_09-00-00.txt
telescope_to_convacpr_2009-05-06_08-53-31.txt
telescope_to_convacop_2009-05-06_08-53-31.txt
telescope_to_convacpr_2009-05-06_08-52-58.txt
telescope_to_convacop_2009-05-06_08-52-58.txt
telescope_to_convacpr_2009-05-06_08-49-49.txt
telescope_to_convacop_2009-05-06_08-49-49.txt
jda_to_telescope_2009-05-05_19-00-02.txt
jda_to_telescope_2009-05-05_17-00-02.txt
jda_to_telescope_2009-05-05_15-00-02.txt
jda_to_telescope_2009-05-05_13-00-01.txt
jda_to_telescope_2009-05-05_11-00-01.txt
jda_to_telescope_2009-05-05_09-00-01.txt
jda_to_telescope_2009-05-05_07-00-01.txt

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” ?

Hope this will make things clearer

Thanks,
Peter

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

I get an error on

every file of source_folder whose name begins with "jda_to_telescope" and name ends with ".txt"

Tried to use another Volume on my Desktop but it gives the same error (translated from Dutch to English):

cannot get every file of “d$:Inetpub:ftproot:record_info_exchange:log:”.

Another Volume:
cannot get every file of “DTP:Peter:”.

-Peter–

Came up with this:

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

–Peter–

Hi Peter,
Yep I needed to put as alias on the source_folder.
Is everything working for you now?
Nik

Hi,
It’s working now.

Thanks a lot!!!

–Peter–