Look at the “Remove files…” option on the choose from list. Help me! What am I doing wrong?
set htmlitemurl to ""
set history to {}
set filehistory to {}
set subcom to {"Add More Files."}
repeat
if subcom is {"Add More Files."} then
set thefile to (choose file)
set founditem to POSIX path of thefile
set itemname to name of (info for thefile)
set history to history & itemname
set filehistory to filehistory & founditem
set htmlcont to ""
set itemurl to "file://" & founditem
set htmlitemurl to htmlitemurl & "<p><font size=\"2\" face=\"Lucida Grande\"><a href=\"" & itemurl & "\">" & itemname & "</></p>" & return as string
end if
set subcom to (choose from list {"Finish", "Add More Files.", "Remove files."} with prompt "What do you want to do?")
if subcom is {"Finish"} then
exit repeat
else if subcom is {"Remove files."} then
set deleteitem to (choose from list history with prompt "Remove.")
repeat with i from 1 to (count history)
set deleteitemurl to filehistory's item i
if deleteitem is history's item i then
exit repeat
end if
end repeat
display dialog htmlitemurl
set AppleScript's text item delimiters to "<p><font size=\"2\" face=\"Lucida Grande\"><a href=\"" & deleteitemurl & "\">" & deleteitem & "</></p>" & return
set htmlitemurl to text item 1 of htmlitemurl as string
display dialog htmlitemurl
end if
end repeat
set htmltop to "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\"\n \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">\n<html xmlns=\"http://www.w3.org/1999/xhtml\" xml:lang=\"en\" lang=\"en\">\n<head>\n\t<meta http-equiv=\"content-type\" content=\"text/html; charset=utf-8\" />\n\t<title>My chosen items.</title>\n</head>\n<body>"
set htmlbottom to "</body></html>"
set htmlfilepath to ((path to desktop) as text) & "file.html"
try
set htmlfile to open for access htmlfilepath with write permission
write htmltop to htmlfile as «class utf8»
write htmlitemurl to htmlfile as «class utf8»
write htmlbotton to htmlfile as «class utf8»
close access htmlfile
on error
try
close access htmlfile
end try
end try
tell application "Safari"
activate
open (htmlfilepath as alias)
end tell
Hi,
RTFD(ictionary)
CHOOSE FROM LIST
.
RESULT:
the list of selected items
deleteitem is a list, even if the user chooses one item.
And consider, that the result is boolean false, if the user presses Cancel
‘deleteitemurl’ needs to begin with “file://”, so that the delimiters match the entry you’re trying to delete from ‘htmlitemurl’.
What did I do wrong now? Try this script:
set htmlitemurl to ""
set history to {}
set filehistory to {}
set subcom to {"Add More Files."}
repeat
if subcom is {"Add More Files."} then
set thefile to (choose file)
set founditem to POSIX path of thefile
set itemname to name of (info for thefile)
set history to history & itemname
set filehistory to filehistory & founditem
set htmlcont to ""
set itemurl to "file://" & founditem
set htmlitemurl to htmlitemurl & "<p><font size=\"2\" face=\"Lucida Grande\"><a href=\"" & itemurl & "\">" & itemname & "</></p>" & return as string
end if
set subcom to (choose from list {"Finish", "Add More Files.", "Remove files."} with prompt "What do you want to do?")
if subcom is {"Finish"} then
exit repeat
else if subcom is {"Remove files."} then
set deleteitem to (choose from list history with prompt "Remove.")
repeat with i from 1 to (count history)
set deleteitemurl to filehistory's item i
if deleteitem is history's item i then
exit repeat
end if
end repeat
set history1 to {}
repeat with i from 1 to (count history)
set deleteitemurl to filehistory's item i
if deleteitem is not history's item i then
set history1 to history1 & history's item i
end if
end repeat
set history to history1
display dialog htmlitemurl
set AppleScript's text item delimiters to "<p><font size=\"2\" face=\"Lucida Grande\"><a href=\"file://" & deleteitemurl & "\">" & deleteitem & "</></p>" & return
set htmlitemurl to text item 1 of htmlitemurl as string
display dialog htmlitemurl
end if
end repeat
set htmltop to "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\"\n \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">\n<html xmlns=\"http://www.w3.org/1999/xhtml\" xml:lang=\"en\" lang=\"en\">\n<head>\n\t<meta http-equiv=\"content-type\" content=\"text/html; charset=utf-8\" />\n\t<title>My chosen items.</title>\n</head>\n<body>"
set htmlbottom to "</body></html>"
set htmlfilepath to ((path to desktop) as text) & "file.html"
try
set htmlfile to open for access htmlfilepath with write permission
write htmltop to htmlfile as «class utf8»
write htmlitemurl to htmlfile as «class utf8»
write htmlbotton to htmlfile as «class utf8»
close access htmlfile
on error
try
close access htmlfile
end try
end try
tell application "Safari"
activate
open (htmlfilepath as alias)
end tell
This always appears on the bottom:
I did not choose that item, and it’s on my desktop!
The bottom of what?
If you mean the bottom of what’s displayed in Safari, it’s probably because you selected it on a previous run and it’s still in the html file. Try setting the eof of the file to 0 first to empty it before you write the new set of data.
I’ve taken the liberty of fiddling with the “Remove files.” sequence to get it to behave as I think it’s meant to.
set htmlitemurl to ""
set history to {}
set filehistory to {}
set subcom to {"Add More Files."}
repeat
if subcom is {"Add More Files."} then
set thefile to (choose file)
set founditem to POSIX path of thefile
set itemname to name of (info for thefile)
set history to history & itemname
set filehistory to filehistory & founditem
set htmlcont to ""
set itemurl to "file://" & founditem
set htmlitemurl to htmlitemurl & "<p><font size=\"2\" face=\"Lucida Grande\"><a href=\"" & itemurl & "\">" & itemname & "</></p>" & return as string
end if
set subcom to (choose from list {"Finish", "Add More Files.", "Remove files."} with prompt "What do you want to do?")
if (subcom is false) then -- Catch the "Cancel" button.
error number -128
else if subcom is {"Finish"} then
exit repeat
else if subcom is {"Remove files."} then
set deleteitem to (choose from list history with prompt "Remove.")
if (deleteitem is false) then error number -128 -- Catch the "Cancel" button.
set deleteitem to item 1 of deleteitem -- Otherwise get the single item from the returned list.
repeat with i from 1 to (count history)
set deleteitemurl to filehistory's item i
if deleteitem is history's item i then
exit repeat
end if
end repeat
(* set history1 to {}
repeat with i from 1 to (count history)
set deleteitemurl to filehistory's item i -- This changes the value of deleteitemurl!
if deleteitem is not history's item i then
set history1 to history1 & history's item i
end if
end repeat
set history to history1 *)
set item i of history to missing value -- Suggested .
set history to history's text
set item i of filehistory to missing value
set filehistory to filehistory's text -- . alternative.
set astid to AppleScript's text item delimiters
set AppleScript's text item delimiters to "<p><font size=\"2\" face=\"Lucida Grande\"><a href=\"file://" & deleteitemurl & "\">" & deleteitem & "</></p>" & return
set htmlitemurl to text items of htmlitemurl
set AppleScript's text item delimiters to ""
set htmlitemurl to htmlitemurl as string
set AppleScript's text item delimiters to astid
end if
end repeat
set htmltop to "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\"
\"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">
<html xmlns=\"http://www.w3.org/1999/xhtml\" xml:lang=\"en\" lang=\"en\">
<head>
<meta http-equiv=\"content-type\" content=\"text/html; charset=utf-8\" />
<title>My chosen items.</title>
</head>
<body>"
set htmlbottom to "</body></html>"
set htmlfilepath to ((path to desktop) as text) & "file.html"
try
set htmlfile to open for access htmlfilepath with write permission
set eof htmlfile to 0 -- Lose any old contents first.
write htmltop to htmlfile as «class utf8»
write htmlitemurl to htmlfile as «class utf8»
write htmlbotton to htmlfile as «class utf8»
close access htmlfile
on error
try
close access htmlfile
end try
end try
tell application "Safari"
activate
open (htmlfilepath as alias)
end tell