Repeat script action with button click/return key

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?

Many thanks,

Bowjest

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?

Thanks,

Bowjest

Hi,

the default folder path contains spaces, so you have to quote the path anyway


do shell script "textutil -convert html " & quoted form of htmlFilePOSIX

Hello!

You have to do like StefanK says!

Use quoted paths, then in your original script you can put in a display dialog so that you make it hang until you click the dialog or hit enter.


tell application "SystemUIServer"
	activate
	try
		display dialog "commence" buttons {"Ok"} default button 1 with icon 1
	end try
end tell

Ah! I see!

I just managed to put this together, but I’ll try your and StefanK’s suggestions as mine doesn’t work. :slight_smile:

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

I’ll be right back.

Thanks, guys!

All working now! Whoo Hoo! :smiley:

Thanks to you both!

I’ll pass this on to the OmegaT guys to add to the HowTo’s!

All the best,

Bowjest

simpler, pressing Cancel aborts the script anyway


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

Thanks, StefanK.

Cleaner and easier.

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

Thanks,
Bowjest

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?

Bowjest

Hello

insert this at some convenient place:


do shell script "rm " & quoted form of POSIX path of htmlFile

Hi McUsr,

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

Thanks for your help.

Bowjest