Hi,
I'm trying to create an Applescript which runs as an application. When run, it prompts the user for a number of hours, then waits this number of hours to launch a specific application, for instance, TextEdit.
For some reason (I think since Yosemite), each first time I open or compile in Applescript, or the application once saved, it starts the target application immediately, before it's even prompted the user. The process repeats if Applescript is closed down and opened again. It never used to do that prior to Yosemite, then seemed to start all of a sudden.
Code is as follows:
I've tried using a block tell/end tell and using activate rather than launch but I get the same thing happening. Also I've tried using a sub-routine with the same result. If I comment out the tell statement, the problem naturally doesn't occur.
I only want the application to launch once the user has submitted the input and assumed the if statement would not execute until this was done. Can anyone advise if/where I am going wrong? I'm aware the code may be messy, and there are likely better ways to do things, but I've not got a lot of experience with Applescript.
Thanks in advance for any help.
I'm trying to create an Applescript which runs as an application. When run, it prompts the user for a number of hours, then waits this number of hours to launch a specific application, for instance, TextEdit.
For some reason (I think since Yosemite), each first time I open or compile in Applescript, or the application once saved, it starts the target application immediately, before it's even prompted the user. The process repeats if Applescript is closed down and opened again. It never used to do that prior to Yosemite, then seemed to start all of a sudden.
Code is as follows:
Code:
set x to text returned of (display dialog "Open TextEdit in {x} hours?" with title "Input value..." default answer "0" buttons {"Cancel", "Start"} default button 2)
set y to x
set x to (x * 60) * 60
if x > 0 then
set myDate to current date
set myNewDate to myDate + (y * hours)
set myTime to time string of myNewDate
set myParts to words of myTime
set myDisplay to (item 1 of myParts) & ":" & (item 2 of myParts)
display dialog "TextEdit will start at " & myDisplay with title "Starting at..." buttons {"Cancel", "Confirm"} default button 2
display notification "Starting TextEdit at " & myDisplay
set input to x
delay input
tell application "TextEdit" to launch
else
display dialog "Cannot be 0 or null." with title "Error..." with icon stop buttons {"Ok"} default button 1
end if
I've tried using a block tell/end tell and using activate rather than launch but I get the same thing happening. Also I've tried using a sub-routine with the same result. If I comment out the tell statement, the problem naturally doesn't occur.
I only want the application to launch once the user has submitted the input and assumed the if statement would not execute until this was done. Can anyone advise if/where I am going wrong? I'm aware the code may be messy, and there are likely better ways to do things, but I've not got a lot of experience with Applescript.
Thanks in advance for any help.