Bonjour à tous.
Je souhaite générer un fichier html dans lequel se trouve le nom de la piste jouée par iTunes ainsi que le nom de l'artiste.
Étant débutant en applescript j'ai eu la chance de tomber sur le script de Doug trackReporter.
Il permet de créer le fichier html que je souhaite.
Cependant j'aurai voulu que le script sépare le nom de la piste et le nom de l'artiste dans deux div différentes.
Voici le code de trackReporter:
Je pense que la partie qui m'interesse se trouve içi:
write "<HTML><HEAD></HEAD><BODY>" & this_data & "</BODY></HTML>" to the open_target_file --starting at eof
J'ai donc essayé de rajouter le code pour deux div, ce qui donne:
write "<HTML><HEAD></HEAD><BODY><div id="titre">" &</div> this_data <div id="artiste">& "</div></BODY></HTML>" to the open_target_file --starting at eof
Bien sur cela ne fonctionne pas.
Si quelqu'un a une petite idée à ce sujet...
Je souhaite générer un fichier html dans lequel se trouve le nom de la piste jouée par iTunes ainsi que le nom de l'artiste.
Étant débutant en applescript j'ai eu la chance de tomber sur le script de Doug trackReporter.
Il permet de créer le fichier html que je souhaite.
Cependant j'aurai voulu que le script sépare le nom de la piste et le nom de l'artiste dans deux div différentes.
Voici le code de trackReporter:
Bloc de code:
-- declare variables for later use
global sample_frequency -- how often we should check iTunes
global itunes_active -- if iTunes is active or not
global User_choice -- option returned from initial dialog display
global data_dir -- directory where log file lives
global file_name -- name of log file
global data_file -- the concatenated directory and name
global theTune -- current song and artist in comma list
global ftp_address -- for ftp upload
global ftp_user -- for ftp upload
global ftp_password -- for ftp upload
global dirty_path -- for ftp upload
global start_disk -- name of the startup disk
-- grab the name of our start up disk
set start_disk to "/" & searchReplace(path to startup disk as string, ":", "")
-- choose local folder to save the file to
set data_dir to choose folder with prompt "Choose the folder to save the local log file to."
-- enter the file name and indicate how often to update it
display dialog "Enter a name for the log file and indicate how often you want to update it:" default answer "currentTrack.html" buttons {"15", "30", "60"} default button 1
set dialogInfo to result
set selectedButton to button returned of dialogInfo
get selectedButton
set sample_frequency to selectedButton
set file_name to text returned of dialogInfo
set data_file to data_dir & file_name
-- enter ftp address and directory
display dialog "Enter the FTP address that you wish to upload the logfile to:" default answer "ftp://ftp.YOURDOMAIN.com"
set dialogInfo to result
set ftp_address to text returned of dialogInfo
-- enter the username
display dialog "Enter the FTP username:" default answer "FTP_USERNAME"
set dialogInfo to result
set ftp_user to text returned of dialogInfo
-- enter the password
display dialog "Enter the FTP password:" default answer "FTP_PASSWORD"
set dialogInfo to result
set ftp_password to text returned of dialogInfo
-- start of monitoring section
on idle
-- check if itunes is running
set itunes_active to false
tell application "Finder"
if (get name of every process) contains "iTunes" then set itunes_active to true
end tell
-- if itunes is running then we are go
if itunes_active then
tell application "iTunes"
-- if itunes is playing
if player state is playing then
-- get info on current track
try
my getCurrentTrack()
my write_to_file(theTune, data_file, true)
my uploadFile()
on error -- playing but not started track yet
my getCurrentTrack()
my write_to_file(theTune, data_file, true)
my uploadFile()
end try
else
-- itunes is active but not playing so check back shortly
set idle_time to 15
end if
end tell
set idle_time to sample_frequency
else
-- itunes is not currently active so wait a minute before checking again
set idle_time to 60
end if
return idle_time
end idle
--
-- subroutineto get the current track from itunes
--
on getCurrentTrack()
tell application "iTunes"
set theTitle to name of current track
set theArtist to artist of current track
end tell
set theTune to theTitle & "|" & theArtist as string
end getCurrentTrack
--function to write the track name to text file and upload it
on write_to_file(this_data, target_file, append_data)
try
set the target_file to the target_file as text
set the open_target_file to open for access file target_file with write permission
--if append_data is false then ¬
set eof of the open_target_file to 0
--write this_data to the open_target_file --starting at eof
-- comment below line out if you don't want HTML headers and footers
write "<HTML><HEAD></HEAD><BODY>" & this_data & "</BODY></HTML>" to the open_target_file --starting at eof
-- Uncomment if you want no HTML headers or footers
--write this_data to the open_target_file --starting at eof
close access the open_target_file
return true
on error error_message number error_number
return error_message
end try
end write_to_file
--
-- subroutine to upload the file
--
on uploadFile()
try
with timeout of 30 seconds
set theText to ":" & data_dir
set dirty_path to searchReplace(theText, ":", "/")
set shellCommand to "cd " & searchReplace(dirty_path, start_disk, "") & ";curl -s -m 120 -T " & file_name & " -u " & ftp_user & ":" & ftp_password & " " & ftp_address
-- ===============================
-- uncomment the next line for debugging
-- ===============================
-- display dialog shellCommand
do shell script shellCommand
end timeout
on error error_message number error_number
tell application (path to frontmost application as text)
beep
display dialog the error_message buttons {"Cancel"} default button 1
end tell
end try
end uploadFile
--
-- subroutine to fix the applescript urls to work with the unix curl command
--
on searchReplace(theText, SearchString, ReplaceString)
set OldDelims to AppleScript's text item delimiters
set AppleScript's text item delimiters to SearchString
set newText to text items of theText
set AppleScript's text item delimiters to ReplaceString
set newText to newText as text
set AppleScript's text item delimiters to OldDelims
return newText
end searchReplace
--
-- sub routine to handle quit requests
--
on quit
my write_to_file("OFFLINE", data_file, true)
my uploadFile()
continue quit
end quit
Je pense que la partie qui m'interesse se trouve içi:
write "<HTML><HEAD></HEAD><BODY>" & this_data & "</BODY></HTML>" to the open_target_file --starting at eof
J'ai donc essayé de rajouter le code pour deux div, ce qui donne:
write "<HTML><HEAD></HEAD><BODY><div id="titre">" &</div> this_data <div id="artiste">& "</div></BODY></HTML>" to the open_target_file --starting at eof
Bien sur cela ne fonctionne pas.
Si quelqu'un a une petite idée à ce sujet...