Exactly what is 'pmset noidle' doing while active? It's not clear to me.
on run
repeat
tell application "Finder"
activate
display dialog "Enter minutes until alarm ..." default answer 1 buttons {"Cancel", "Start"} default button 2
end tell
try
set minToAlarm to (text returned of the result) as integer
if minToAlarm > 0 then exit repeat
end try
end repeat
set alarmTime to ((current date) + 60 * minToAlarm) -- adding seconds
---------------------------------
try
do shell script "pmset noidle >/dev/null 2>&1 & echo $!" --****************
set pid to the result
on error errtext number errNr
"Error = " & errNr & return & errtext
display dialog the result buttons {"OK"} default button 1
return
end try
display dialog "Begin time out ..."
---------------------------------
repeat
if (current date) > alarmTime then exit repeat
delay 10
end repeat
do shell script "kill " & pid --*******************
repeat 20 times
beep
delay 1
end repeat
end run