Applescript Expected “"” but found end of script - syntax-error

So, this is what I have wrote so far, the web links are censored for privacy reasons. I made this script so I could have an easy way to access all of my class links. After I told the program to quit after it completed its task, It would not save for the life of me. This is my code:
display dialog "Where would you like to go?" buttons {"Math", "English", "Other"} default button 3
set the button_pressed to the button returned of the result
if the button_pressed is "Math" then
display dialog "Select which math you would like to access." buttons {"Math", "Science", "Quit"} default button 3
set the button_pressed to the button returned of the result
if the button_pressed is "Math" then
display dialog "Select which math you would like to access." buttons {"Mathway", "Powerschool", "Quit"} default button 3
set the button_pressed to the button returned of the result
if the button_pressed is "Mathway" then
tell application "Google Chrome"
activate
open location "https://www.mathway.com/Algebra"
end tell
delay 1
tell application "Google Chrome" to activate
tell application "School Shortcuts" to quit
else if the button_pressed is "Powerschool" then
tell application "Google Chrome"
activate
open location "_"
end tell
delay 1
tell application "Google Chrome" to activate
else
tell application "School Shortcuts" to quit
end if
else if the button_pressed is "English" then
display dialog "Select which math you would like to access." buttons {"Science Calculators", "Powerschool", "Quit"} default button 3
set the button_pressed to the button returned of the result
if the button_pressed is "Science Calculators" then
tell application "Google Chrome"
activate
open location "https://www.google.com/search?q=science+calculator&oq=science+calculator&aqs=chrome..69i57j0l9.6020j0j7&sourceid=chrome&ie=UTF-8"
end tell
delay 1
tell application "Google Chrome" to activate
tell application "School Shortcuts" to quit
else if the button_pressed is "Powerschool" then
tell application "Google Chrome"
activate
open location "_"
end tell
delay 1
tell application "Google Chrome" to activate
else
tell application "School Shortcuts" to quit
end if
else
tell application "School Shortcuts" to quit
end if
else
display dialog "Select which you would like to access." buttons {"Spanish", "Comp Tech", "Quit"} default button 3
set the button_pressed to the button returned of the result
if the button_pressed is "Spanish" then
display dialog "Spanish" buttons {"Google Classroom", "Translate", "Quit"} default button 3
set the button_pressed to the button returned of the result
if the button_pressed is "Google Classroom" then
tell application "Google Chrome"
activate
open location "_"
end tell
delay 1
tell application "Google Chrome" to activate
else if the button_pressed is "Translate" then
tell application "Google Chrome"
activate
open location "https://www.google.com/search?q=translate&oq=translate&aqs=chrome.0.69i59j0j0i433j0j0i433j69i60l3.1944j0j7&sourceid=chrome&ie=UTF-8"
end tell
delay 1
tell application "Google Chrome" to activate
else
tell application "School Shortcuts" to quit
end if
else if the button_pressed is "Comp Tech" then
display dialog "Comp Tech" buttons {"Google Classroom", "Youtube", "Quit"} default button 3
set the button_pressed to the button returned of the result
if the button_pressed is "Google Classroom" then
tell application "Google Chrome"
activate
open location "_"
end tell
delay 1
tell application "Google Chrome" to activate
else if the button_pressed is "Youtube" then
tell application "Google Chrome"
activate
open location "youtube.com"
end tell
delay 1
tell application "Google Chrome" to activate
else
tell application "School Shortcuts" to quit" to quit
end if
else
end if
end if
end
If you have any idea on why it is doing this, I would greatly appreciate it.

The error
Expected “"” but found end of script
indicates an unbalanced double quote.
At the end of the script there it is
tell application "School Shortcuts" to quit" to quit
Delete the (last) double quote and the rest of the line
tell application "School Shortcuts" to quit

Related

Wait for hotkey?

I'm wondering why my script doesn't wait for me to send the hotkey Alt + Shift + q?
WinWaitActive("Open")
HotKeySet("+!q", "ClickFill")
Func ClickFill()
ControlClick("Open", "", "[CLASS:32770]")
ControlSend("Open", "", "[CLASS:32770]", "C:\au3")
Exit
The script just exits after the 'Open' dialog becomes active. I'm trying to get the script to click on class 32770, which is the address bar, then send the au3 directory to it, which is my autoit scripts directory. My hope is that the script will always stay open, so any time I try to open something, it works.
Second attempt
WinWaitActive("Open")
HotKeySet("+!q", "ClickFill")
While(1)
Sleep(1000)
WEnd
Func ClickFill()
ControlClick("Open", "", "[CLASS:32770]")
ControlSend("Open", "", "[CLASS:32770]", "C:\au3")
Exit
The script remains open, but the hotkey is not effective.
It looks like you just need to close your function with a "EndFunc". This works for me.
WinWaitActive("Open")
HotKeySet("+!q", "ClickFill")
While(1)
Sleep(1000)
WEnd
Func ClickFill()
MsgBox(262144,"","Look I work!")
ControlClick("Open", "", "[CLASS:32770]")
ControlSend("Open", "", "[CLASS:32770]", "C:\au3")
Exit
EndFunc
Here is some working code for Notepad++
Global $g_hWinHandle, $g_hOpenWin
;set hotkey
HotKeySet("+!q", "ClickFill")
;open notepad++
ShellExecute(#ProgramFilesDir & "\notepad++\notepad++.exe")
;wait for notepad++ window
WinWait("[Class:Notepad++]")
If #error Then Exit
;get notepad++ window handle
$g_hWinHandle = WinGetHandle("[Class:Notepad++]")
;make sure the window is active
WinActivate($g_hWinHandle)
WinWaitActive($g_hWinHandle)
;open "Open" dialog
WinMenuSelectItem($g_hWinHandle, "", "&File", "&Open...")
;wait for "Open" dialog window
WinWaitActive("Open")
;get the "Open" dialog window handle
$g_hOpenWin = WinGetHandle("Open")
If #error Then Exit
;wait for hotkey
While (1)
Sleep(1000)
WEnd
Func ClickFill()
;make sure the window is active
WinActivate($g_hOpenWin)
WinWaitActive($g_hOpenWin)
;focus the toolbar
ControlFocus($g_hOpenWin, "", "[CLASS:ToolbarWindow32; INSTANCE:3]")
ControlCommand($g_hOpenWin, "", "[CLASS:ToolbarWindow32; INSTANCE:3]", "SendCommandID", "1280")
;send our command to the toolbar
ControlSetText($g_hOpenWin, "", "Edit2", "C:\au3")
ControlSend($g_hOpenWin, "", "Edit2", "{ENTER}")
Exit
EndFunc ;==>ClickFill
In the above example you will see that I use ControlFocus and ControlCommand on the ToolbarWindow32 control. Most dialog windows have a ToolbarWindow32 control. To simulate clicking on them you have to use ControlCommand with the SendCommandID option. You can get that ID under the toolbar tab in the AutoIt info tool. However, you will see that once the ToolbarWindow32 control is clicked on it gives focus to an edit control. That edit control is what you need to send text to if you want to change directories. Finding that edit control with the AutoIt tool can be a bit tricky. You will have to make sure "Freeze" is unchecked under options.
If you are still having problems with the code I would recommend that you first make sure you can get the code working without a hotkey. Then try it with a one letter hotkey and then lastly try it with your multiple hotkey combination. With out having access to your computer I am just guessing but I suspect that you are not accessing the address bar right. There might also be a program running on your computer that is using the same hotkey.

Why is return from MessageBox.Show not "DialogResult.Cancel" when the close button is pressed?

I'm using the following code:
Dim Reply As DialogResult = MessageBox.Show("GOT IT!")
If Reply = DialogResult.OK Then '...`
When I click the Close button (red "X" in corner) the condition looking for DialogResult.OK still evaluates to true and when I check the Reply variable's value at runtime after clicking the close button it is 1 {OK}.
From the documentation on MessageBox Class it says:
Displays a message window, also known as a dialog box, which
presents a message to the user. It is a modal window, blocking other
actions in the application until the user closes it. A MessageBox can
contain text, buttons, and symbols that inform and instruct the user.
While I find the documentation on DialogBoxes a little convoluted and confusing, it appears to me (and i could be bery wrong) that the Close button should by default set the return to IDCancel which, I must assume is somehow parsed by the MessageBox class into DialogReturn.Cancel.
So why does MessageBox not show the return form the close button as DialogResult.Cancel??
This is all very confusing to me because it seems the MessageBox class is not consistent with other forms from within the same Systems.Windows.Forms namespace.
For instance, if we look at the documentation from the Form Class's .DialogResult method, it specifically tells us the return from the close button is DialogResult.Cancel:
When a form is displayed as a modal dialog box, clicking the Close
button (the button with an X in the top-right corner of the form)
causes the form to be hidden and the DialogResult property to be set
to DialogResult.Cancel.
As already stated in the comments above, you could get IDCancel result when clicking the Close Red Button, only if you add a MessageBoxButtons enum that include the Cancel option For example MessageBoxButtons.OKCancel and others.
The MessageBox.Show method is indeed a wrapper around the WinApi MessageBox function. You could see this wrapping looking at the reference sources
The behavior of MessageBox.Show is different from the link that you have pointed. That one is relative to the WinForm engine and of course the behavior of the WinForm Form class is totally managed by the library to handle the scenarios presumed for a WinForm class.
In the WinApi documentation you could find a subtle reference in the section about the Return value where they talks about the behavior when the cancel button is present. Then trial and error confirms this assumption.
You need to pass in MessageBoxButtons as an override that includes a cancel button so like MessageBoxButtons.OKCancel.
Dim message As String = "GOT IT!"
Dim caption As String = "Fancy Caption"
Dim Reply As DialogResult = MessageBox.Show(message, caption, MessageBoxButtons.OKCancel)
If Reply = DialogResult.OK Then '...`
If you dont want the caption than skip it but you'll still need a comma, like:
MessageBox.Show("GOT IT!",,MessageBoxButtons.OKCancel)
See here for full enumeration of options for MessageBoxButtons.

Autoit and notepad

I have an application, wherein I get a "Save As" dialog-box. At times, if a file exists with the same name, then another dialog box comes in, with the same name "Save As". The following is the code, which I wrote but it doesn't work as expected.
Global $sTitle = "Save As"
WinWait($sTitle)
WinWaitActive($sTitle)
ControlClick($sTitle, "Save", "[CLASS:Button; TEXT:&Save; INSTANCE:2]")
ControlSetText($sTitle, "", "CLASS:Button; INSTANCE:2]", $file_name)
SendKeepActive($sTitle)
Send("{ENTER}")
Sleep(4000)
WinWaitActive($sTitle,"",3)
If WinExists($sTitle, "No") Then Send("{ENTER}")
If WinExists("Exit OmniPeek") Then
Send("{ENTER}")
Else
Sleep(2000)
WinClose($closing_file)
EndIf
The idea is to check if the second "Save As" dialog box comes and if does come in, then over-write the existing file. This however, doesn't seem to be working with the autoit script that I wrote.
Can someone help me with this script? You can re-create the issue by using Notepad as well. Just have a file with a name abc.txt and try to save a file with the same name
You will get another dialog box with the name "Save As".
Try this:
Example()
Func Example()
; Run Notepad
Run("notepad.exe")
; Wait 10 seconds for the Notepad window to appear.
Local $hWnd = WinWait("[CLASS:Notepad]", "", 10)
; Keep the Notepad window active when using the Send function.
SendKeepActive("[CLASS:Notepad]")
; Simulate entering a string of text. If you try to change to a different window other than Notepad, then the Notepad window will
; be brought to focus again.
For $i = 1 To 10
Sleep(5)
Send("notepad - ")
Next
; Disable the Notepad window being active when using the Send function.
SendKeepActive("")
; Close the Notepad window using the handle returned by WinWait.
WinClose($hWnd)
Send("{ENTER}") ; <<< SAVE
; Now a screen will pop up and ask to save the changes, the classname of the window is called
; "#32770" and simulating the "TAB" key to move to the second button in which the "ENTER" is simulated to not "save the file"
WinWaitActive("[CLASS:#32770]", '', 2)
Sleep(50)
Send('newName.txt')
Sleep(1000)
Send("{TAB}{ENTER}")
EndFunc ;==>Example

Rebol Cannot close view window on Mac OS X and I cannot enter anything in field

I cannot close window on Mac OS X 10.6.4 and I cannot enter anything in field. REBOL/View 2.7.7.2.5 5-Jan-2010
Update: this occurs when I escape the console program I executed here http://askcodegeneration.com/rebol-form/
window: layout [
H1 "Demo"
style rightlabel label right 120x24
across
rightlabel "First Name" First-Name: field "Enter First Name" Return rightlabel "Last Name" Last-Name: field "Enter Last Name" Return rightlabel "Age" Age: field "Enter Age" Return rightlabel "Note" Note: Area "Enter Note" Return
rightlabel
space 0
button "Submit" [
;close the window for the program to continue
unview
]
button "Cancel" [unview]
]
View Window
anytime you escape in the console, the event management stops.
just do do-events to start up even handling again.
closing the console window should always closes all view windows.

Keep Popup Window in WebBrowser control instead of a new window

When using the WebBrowser control, is it possible to cause popup windows to
appear within the WebBrowser control itself instead of a new window?
I can't figure out how to get the popup to appear in the same browser window. please help me :)
PS : The language I use is VB
If you have multiple tabs with WebBrowsers, use this under the "New Window" Event:
((WebBrowser)TabControl1.SelectedTab.Controls[0]).Navigate(((WebBrowser)
TabControl1.SelectedTab.Controls[0]).StatusText)
'next input <cancel[IE]>
e.Cancel = True
If just a plain browser put this under the New Window Event:
webBrowser1.Navigate(webBrowser1.StatusText)
e.Cancel = True