Hello,
Here is the final script, I do not know if we can simplify it because it must work 24 hours a day, therefore interrogate the text file concerned.
use AppleScript version "2.4" -- El Capitan (10.11) or later
use scripting additions
tell application "Finder"
with timeout of 86400 seconds
-- step 1: select a random file
set random_file to (file "rds_espace.txt" of folder "titre" of desktop) as alias
-- step 2: read the first line of the file contents
set file_contents to paragraph 1 of (read random_file)
-- step 3: break out the artist and track names
set {theArtist, theTitle} to my getTrack(file_contents)
-- step 4: reconstruct the data in the required format
set nowPlayingData to "Title: " & theTitle & return & linefeed & "Artist:" & theArtist as text
-- and write it to the file
set npFile to open for access ((file "NowPlaying.txt" of (folder "Nicecast" of (get path to application support from user domain))) as alias) with write permission
-- clear the existing file content
set eof npFile to 0
-- write the new data
write nowPlayingData to npFile
-- and close the file
close access npFile
end timeout
end tell
on getTrack(theText)
set {oldTID, my text item delimiters} to {my text item delimiters, "-"}
set w1 to text item 1 of theText
set w2 to text item 2 of theText
set my text item delimiters to oldTID
return {w1, w2}
end getTrack
tell application "WinMedia" -- the name I gave to the original script
repeat
activate
delay 2
quit
delay 4
end repeat
end tell
Regards
Vincent M