Welcome to MacForumz.com!
FAQFAQ      ProfileProfile    Private MessagesPrivate Messages   Log inLog in

text file nightmare

 
Goto page Previous  1, 2, 3
   Macintosh computer (Home) -> Apple Scripts RSS
Next:  mac os x authentication on pdc samba  
Author Message
biz

External


Since: Dec 31, 2007
Posts: 25



(Msg. 31) Posted: Thu Jan 31, 2008 7:16 pm
Post subject: Re: text file nightmare [Login to view extended thread Info.]
Archived from groups: alt>comp>lang>applescript (more info?)

Got a bit further. Problems happen when there are (sub) folders of the
same name. In other words if a path contains an identical folder name
to another folder from one of the songs even if they are not adjacent
the the script goes back to way back to change the path of a previous
song to the path of the song currently processed. For instance, first
the script writes the correct path to a song "Users/kurtp/Music/iTunes/
iTunes Music/Mad Professor/Axiom Dub-Mysteries of Creation" and then
when it gets to another song it writes the path for that song
correctly to: "/Users/kurtp/Music/iTunes/iTunes Music/Dub Syndicate/
Axiom Dub-Mysteries of Creation" but then goes back and changes the
first path incorrectly to "Users/kurtp/Music/iTunes/iTunes Music/Dub
Syndicate/Axiom Dub-Mysteries of Creation". I'll keep on working. This
is my 3rd day with 3hours of sleep with continuous work and little
food. I haven't gone to work and I have to solve this before I can go
on with my life. Thank yo

 >> Stay informed about: text file nightmare 
Back to top
Login to vote
Jolly Roger

External


Since: Sep 09, 2006
Posts: 3119



(Msg. 32) Posted: Thu Jan 31, 2008 10:08 pm
Post subject: Re: text file nightmare [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

In article
<e009ce5f-eca7-41c3-9158-b86a6746e0a5 RemoveThis @i12g2000prf.googlegroups.com>,
biz RemoveThis @theplayspace.com.au wrote:

(snip)

By the way, you shouldn't be manually changing paths from HFS paths
(HD:folder:folder) to POSIX paths (/Users/folder/folder/). There's a
built-in property for that:

set hfsPath to the path to the desktop from the user domain
set posixPath to hfsPath's POSIX path
log hfsPath
log posixPath

--
Note: Please send all responses to the relevant news group. If you
must contact me through e-mail, let me know when you send email to
this address so that your email doesn't get eaten by my SPAM filter.

JR

 >> Stay informed about: text file nightmare 
Back to top
Login to vote
Kurt Klamp

External


Since: Feb 01, 2008
Posts: 3



(Msg. 33) Posted: Thu Jan 31, 2008 10:29 pm
Post subject: Re: text file nightmare [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

Oh man (woman? ['Karo' is male|female ?]),


<biz RemoveThis @theplayspace.com.au> wrote:

> Thanks for the suggestion about XML but it is simply impossible for me
> to start studying a whole new matter now.

No fear, new experiences/fields are supposed to widen the horizon :-)

>I did improve the script by
> reducing some code and making the routine to rename the path much
> shorter and easier. Still, it does not work as it fills in the wrong
> values in long file. It works perfectly on short files. I really want
> this to work before I go insane. Thank you.

you are welcome.

My last attempt:
If you are willing to risk entering a new field i'll try to show you the
'xml'-way (with a learning curve near zero). The only thing required by
you is to install the 'Smile' package.
<http://www.satimage.fr/software/downloads/Smile323regular.dmg>
If you agree i'll post a script tomorrow, which should fit your needs.

Kurt

--
if you want to send me your info:
k dot klamp at t-online dot de
 >> Stay informed about: text file nightmare 
Back to top
Login to vote
Joseph.B

External


Since: Jan 26, 2008
Posts: 7



(Msg. 34) Posted: Thu Jan 31, 2008 10:29 pm
Post subject: Re: text file nightmare [Login to view extended thread Info.]
Imported from groups: per prev. post (more info?)

Back to top
Login to vote
Kurt Klamp

External


Since: Feb 01, 2008
Posts: 1



(Msg. 35) Posted: Fri Feb 01, 2008 9:54 am
Post subject: Re: text file nightmare [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

<biz.TakeThisOut@theplayspace.com.au> wrote:

> HI Joseph. It's not about the paragraph definition since the
> (sometimes wrong) file paths are exactly placed where they should be.
> I'll try the log. Hi Kurt. I did install smile.

Fine

>What's next. Thank you.


OK here we go:

1. make a copy of the the original text file (XML file)
2. a) launch Smile and choose 'new-> script'
or
2.b) launch ScriptEditor and choose 'new'
3. copy the script below into the window
4. run the script
5. tell us whats going on

-- script using xmllib.osax
property x_file : "path to your textfile"
property p : "" -- holds the xml ref
property ml : "" -- holds ref to the itunes playlist
property tr : "" -- holds refs to found tracks

-- init
tell application "iTunes" to set ml to library playlist 1

try
set x_file to (alias x_file)
on error
set x_file to choose file with prompt "Select the text input file!"
end try

try
set p to XMLOpen x_file
set _entries to XMLCount p
repeat with i from 1 to _entries
set p1 to XMLChild p index i with all nodes
set {artistname, songname} to XMLGetAttribute p1 name {"ARTIST",¬
"TITLE"}
set tr to missing value
try
tell application "iTunes"
set tr to (file tracks of ml whose (artist is artistname¬
and name is songname))
if (count tr) is 1 then
set t1 to get item 1 of tr
set fullpath to (location of t1)
else
error "wrong match"
end if
end tell
set _info to (info for fullpath)
set fname2 to name of _info
tell application "Finder" to set path2 to POSIX path of¬
(folder of fullpath as string)
set p2 to XMLXPath p1 with "LOCATION"
XMLSetAttribute p2 name {"DIR", "FILE"} to {path2, fname2}
on error s
log s
end try
end repeat
on error s number n
log s & return & n
XMLSave p
end try
XMLSave p
XMLClose p

-- end script


be aware of line breaks.


Try and report,

hth,
Kurt
 >> Stay informed about: text file nightmare 
Back to top
Login to vote
Joseph.B

External


Since: Jan 26, 2008
Posts: 7



(Msg. 36) Posted: Fri Feb 01, 2008 9:54 am
Post subject: Re: text file nightmare [Login to view extended thread Info.]
Imported from groups: per prev. post (more info?)

Back to top
Login to vote
biz

External


Since: Dec 31, 2007
Posts: 25



(Msg. 37) Posted: Fri Feb 01, 2008 4:06 pm
Post subject: Re: text file nightmare [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

Hi guys. I figured it out. I used a different way to substitute text
in text edit (by installing TextCommands). I still have to do a fair
bit of manual editing in the DJ program but that has nothing to do
with the script. It now works fine. Thanks alot for everyone's input.
Karo.
My final script:
global allText
global filePath
global fileName
global artistName
global songName
global fileName2
global filePath2
global counter
global flag
global TheLocationText


set counter to 2
repeat with x from 1 to 1810

tell application "TextEdit"
set AppleScript's text item delimiters to "<ENTRY"
set allText to text of document 1
set textItems to text items of allText

set parag to text item counter of textItems


if parag does not contain "ARTIST=" then
set counter to counter + 1
set parag to text item counter of allText


if parag does not contain "ARTIST=" then
set counter to counter + 1
set parag to text item counter of allText


end if

end if

if parag contains "&" then
set counter to counter + 1
set parag to text item counter of allText

if parag contains "&" then
set counter to counter + 1
set parag to text item counter of allText

if parag contains "&" then
set counter to counter + 1
set parag to text item counter of allText

if parag contains "&" then
set counter to counter + 1
set parag to text item counter of allText

if parag contains "&" then
set counter to counter + 1
set parag to text item counter of allText

end if
end if
end if
end if
end if

set AppleScript's text item delimiters to "\""
set artistName to text item 2 of parag as text --First match
criteria
set songName to text item 6 of parag as text --Second match
criteria
set AppleScript's text item delimiters to " "
set line2 to text item 2 of parag
set AppleScript's text item delimiters to "\""
set filePath to text item 2 of line2 as text ----that's what needs
to be replaced with value of filePath2
set fileName to text item 4 of line2 as text --that's what also
needs to be replaced with value of fileName2
end tell

tell application "iTunes"

try
set TheTrack to (track 1 of library playlist 1 whose artist is
artistName and the name is songName)
set TheLocation to location of TheTrack as string
set TheLocationText to text of TheLocation
set flag to 1 -- using a flag in case iTunes cannot find a song for
some reason
on error
set flag to 0
end try
end tell

set text item delimiters to ":" -- now a path like
"Disk:Users:kurtp:Music:iTunes" is converted to a path like "Disk/
Users/kurtp/Music/iTunes" which is how my DJ program describes files.
set y to text items of TheLocationText
set r to the count of text items of y
set f to text items 1 through -2 of y
set fileName2 to text item -1 of y

set newPathTemp to "/" & text item 2 of y

set d to 3
repeat with i from 1 to (r - 3)
set newPathTemp to newPathTemp & "/" & text item d of y
set d to d + 1
end repeat
get newPathTemp
set filePath2 to newPathTemp & "/"



tell application "TextEdit"
if flag = 1 then

tell application "TextCommands"
set replace1 to search parag for fileName replacing with fileName2
set replace2 to search replace1 for filePath replacing with
filePath2

set replaceWhole1 to search allText for parag replacing with
replace2

end tell
set text of document 1 to replaceWhole1
else
set flag to 1
end if

end tell
set counter to counter + 1

end repeat
 >> Stay informed about: text file nightmare 
Back to top
Login to vote
Display posts from previous:   
Related Topics:
matching phrases from text file - Hi, I'm reading in a file with phrases on seperate lines. How can I then treat the phrases as phrases and not as seperate words when I read it in? e.g. set theFile to "DT's Disk:A Folder:myFile" open for access theFile set fileContents to (rea...

extract text from clipping file - Is this possible to do somehow? I would like to convert a few clipping files to .txt files. -- Koncept << "Contrary to popular belief, the most dangerous animal is not the lion or tiger or even the elephant. The most dangerous animal is a ...

Searching for a string in a text file - Hi, If I want to search for a string in a text file, how should I do it? For Example if I want to check whether textfile1 contains the string "abcdefghij klmnop" or not, then how would I do it? Thanks for your help!

Monitoring the activity of a text file in AS - I have a UNX command that I execute via a 'do shell script' statement in an AS script.It reports its progress by writing to stdout.I can redirect the output to a text file, I can put the UNIX commadn into the background so that the 'do shell script'..

Save text file with DOS linebreaks - I¹ve got a script that writes a playlist in M3U format for an mp3 player. The M3U format is a text file that uses DOS line breaks. Is there any way I can create these types of linebreaks using either TextEdit or Tex-Edit Plus? Currently, I build the fil...
   Macintosh computer (Home) -> Apple Scripts All times are: Pacific Time (US & Canada) (change)
Goto page Previous  1, 2, 3
Page 3 of 3

 
You can post new topics in this forum
You can reply to topics in this forum
You can edit your posts in this forum
You can delete your posts in this forum
You can vote in polls in this forum



[ Contact us | Terms of Service/Privacy Policy ]