I’d like to be able to launch the script below and convert a docx file to HTML format, but then have the script either wait for me to click a button/hit return and repeat the conversion (i.e. update the HTML file created) or click another button and close the app.
Here is my script:
set default_folder_Location to (path to home folder as text) & "01 Translations:03 Projects:"
set htmlFile to (choose file with prompt "File to convert:" default location alias default_folder_Location) as text
do shell script "textutil -convert html " & htmlFile
This, however, fails to create the HTML file. I had it working previously with this script:
set default_folder_Location to (path to home folder as text) & "01 Translations:03 Projects:"
set htmlFolder to (choose folder with prompt "File to convert:" default location alias default_folder_Location) as text
set htmlFolderPOSIX to POSIX path of htmlFolder -- POSIX path representation of project_location
repeat
do shell script "cd " & quoted form of htmlFolderPOSIX & " ; textutil -convert html * "
-- do shell script "cd " & quoted form of htmlFolderPOSIX & " ; textutil -convert html * " & " " & Output & " "
delay 2
end repeat
But this was making my laptop run hot and I had no way to stop it other than a forced quit and it was making my computer run hot. Not good.
If I chance the line above to:
do shell script "echo " & htmlFile
It correctly quotes the file and its path, so am a little lost on why it doesn’t create the target HTML file.
Can anyone advise how to fix this and make the script just wait for a button click or the enter key before executing again?
I’ve tried updating the script with the following, but it still fails to convert the named file:
set default_folder_Location to (path to home folder as text) & "01 Translations:03 Projects:"
set htmlFile to (choose file with prompt "File to convert:" default location alias default_folder_Location) as text
set htmlFilePOSIX to POSIX path of htmlFile
do shell script "textutil -convert html " & htmlFilePOSIX
Can anyone advise why it will read the folder contents (as outlined in my initial post on this topic), but it won’t work on a single file?
I just managed to put this together, but I’ll try your and StefanK’s suggestions as mine doesn’t work.
set default_folder_Location to (path to home folder as text) & "01 Translations:03 Projects:"
set htmlFile to (choose file with prompt "File to convert:" default location alias default_folder_Location) as text
set cancelMe to false
repeat until cancelMe
set alert to display dialog "Update File" buttons {"Cancel", "Update"} default button "Update"
if result = {button returned:"Update"} then do shell script "textutil -convert html " & htmlFile
end repeat
end
set default_folder_Location to (path to home folder as text) & "01 Translations:03 Projects:"
set htmlFile to (choose file with prompt "File to convert:" default location alias default_folder_Location)
repeat
display dialog "Update File" buttons {"Cancel", "Update"} default button "Update"
do shell script "textutil -convert html " & quoted form of POSIX path of htmlFile
end repeat
I’d like to bring Opera forward after the update as that’s the window I will need to check to see how the change has been reflected, but when I added some extra bits to bring it to the front, the system makes an annoying “bonk!” noise.
Is there any way to suppress this?
Here what I added:
set default_folder_Location to (path to home folder as text) & "01 Translations:03 Projects:"
set htmlFile to (choose file with prompt "File to convert:" default location alias default_folder_Location)
repeat
display dialog "Update File" buttons {"Cancel", "Update"} default button "Update"
do shell script "textutil -convert html " & quoted form of POSIX path of htmlFile
tell application "System Events"
tell application "Opera" to activate
end tell
end repeat
Is it possible to make this script delete the file it creates on exit?
Here is the script as I’m currently using it:
set default_folder_Location to (path to home folder as text) & "01 Translations:03 Projects:"
set htmlFile to (choose file with prompt "File to convert:" default location alias default_folder_Location)
tell application "Finder"
reveal htmlFile
do shell script "textutil -convert html " & quoted form of POSIX path of htmlFile
end tell
repeat
display dialog "Update File" buttons {"Cancel", "Update"} default button "Update"
do shell script "textutil -convert html " & quoted form of POSIX path of htmlFile
tell application "System Events"
tell application "Opera" to activate
end tell
end repeat
Would I need to set up some If statements to handle the repetition of the update action and the delete on exit?
I think I must be inserting that in the wrong place as it doesn’t delete the created HTML file when I click cancel and end the script (or perhaps I need to replace the cancel button with an exit - not sure).
Here is what I have:
-- extend the default 2 minute timeout
with timeout of (30 * 60) seconds
-- set path relative to home folder
set default_folder_Location to (path to home folder as text) & "01 Translations:03 Projects:"
set htmlFile to (choose file with prompt "File to convert:" default location alias default_folder_Location)
tell application "Finder"
reveal htmlFile
do shell script "textutil -convert html " & quoted form of POSIX path of htmlFile
tell application "System Events"
tell application "Opera" to activate
end tell
end tell
repeat
display dialog "Update HTML File" buttons {"Cancel", "Update"} default button "Update"
do shell script "textutil -convert html " & quoted form of POSIX path of htmlFile
tell application "System Events"
tell application "Opera" to activate
end tell
end repeat
do shell script "rm " & quoted form of POSIX path of htmlFile
-- end timeout
end timeout