I have a applescript I have been using for a while and it works good:
set js to "document.getElementsByClassName('The_Class')[0].click();"
tell application "Google Chrome" to tell ¬
the front window to tell ¬
the active tab to ¬
set jsResult to execute javascript js
Now I want to add a if and else to it. Like this but I can't find a way to solve it:
if the class ('The_Class') exist then
set js to "document.getElementsByClassName('The_Class')[0].click();"
tell application "Google Chrome" to tell ¬
the front window to tell ¬
the active tab to ¬
set jsResult to execute javascript js
else
tell application "Google Chrome" to activate
tell application "System Events"
keystroke "r" using {command down}
end tell
end if
Related
I have an Outlook VBA macro that does a regex replacement of some text in a reply/forward e-mail, using the WordMail representation of the e-mail.
I can trigger it from a button added to the ribbon. I want it to execute automatically immediately the inspector has opened, i.e. remove the need to remember to press the button once the editor is displayed. I have tried overloading the Open event, but the message does not appear to be accessible at that point - I think this gets invoked too early. None of the other events appears to be at the correct time.
Thank you for any suggestions.
There are multiple events that you consider handling for such purposes.
The very first option is to handle the NewInspector event which is fired whenever a new inspector window is opened, either as a result of user action or through program code The inspector that was opened is passed as a parameter, so you can subscribe to the Activate event which is fired when an inspector becomes the active window, either as a result of user action or through program code. So, at this stage the item and the inspector window have been initialized and you are free to do any customizations.
You may find the Implement a wrapper for inspectors and track item-level events in each inspector article helpful.
The second option is to handle the MailItem.Reply event which is fired when the user selects the Reply action for an item, or when the Reply method is called for the item, which is an instance of the parent object.
Inspectors.NewInspector event
Occurs whenever a new inspector window is opened, either as a result of user action or through program code
Option Explicit
' In ThisOutlookSession
Private WithEvents myOlInspectors As Inspectors
Private Sub Application_Startup_Temporary()
Set myOlInspectors = Application.Inspectors
End Sub
Private Sub myOlInspectors_NewInspector(ByVal oInspector As Inspector)
' https://learn.microsoft.com/en-us/office/vba/api/outlook.inspectors.newinspector
' Occurs whenever a new inspector window is opened,
' either as a result of user action or through program code
Dim msg As MailItem
If oInspector.CurrentItem.Class = olMail Then
Set msg = oInspector.CurrentItem
If msg.Size > 0 Then
Debug.Print "Subject: " & msg.subject
Debug.Print " Non-zero size message opened."
' Your code here
End If
End If
End Sub
Private Sub myOlInspectors_NewInspector_Test()
myOlInspectors_NewInspector ActiveInspector
End Sub
I have a button to perform a task and if an error occurs during the process a warning is displayed using NSAlert "Sheet window"
in this moment I am using multiple .XIB files in a project, I can't display the "Sheet window" in these files(.XIB) is there any way to do this?
Thanks in advance!
on clickedButton:sender
try
--some code here...
on error errorMsg
set alert to current application's NSAlert's alloc's init()
tell alert
its setMessageText:"This is an ERROR"
its setInformativeText: "Error: " & errorMsg
its setAlertStyle:2
its beginSheetModalForWindow:theWindow modalDelegate:me didEndSelector:(missing value) contextInfo:(missing value)
end tell
end try
end clickedButton:
If you don't have a window to put the sheet on, you will need to run the normal alert dialog. You can test for a window by using NSApp's mainWindow(), which will be missing value if there isn't one, and do either alert's runModal() or the sheet depending on the result:
use framework "Cocoa"
use scripting additions
property theWindow : missing value -- this will be the main window...
property sheetOrNot : true -- ... or not, depending on this flag
on run -- this lets the example run from the Script Editor if you forget the main thread thing
my performSelectorOnMainThread:"doWindow" withObject:(missing value) waitUntilDone:true
my performSelectorOnMainThread:"doAlert" withObject:(missing value) waitUntilDone:true
end run
on doWindow() -- create a window to play with
set theWindow to current application's NSWindow's alloc's initWithContentRect:{{200, 400}, {400, 200}} styleMask:7 backing:(current application's NSBackingStoreBuffered) defer:true
set theWindow's releasedWhenClosed to true
if sheetOrNot then tell theWindow to makeKeyAndOrderFront:me
end doWindow
on doAlert() -- show the alert
try
--some code here...
error "oops" -- ...that went badly
on error errorMsg
set alert to current application's NSAlert's alloc's init()
tell alert
its setMessageText:"This is an ERROR"
its setInformativeText:("Error: " & errorMsg)
its setAlertStyle:2
if current application's NSApp's mainWindow() is not missing value then
its beginSheetModalForWindow:theWindow modalDelegate:me didEndSelector:(missing value) contextInfo:(missing value)
else -- no window, so do a normal modal dialog
its runModal()
end if
end tell
end try
end doAlert
By using powershell command I can get the run dialog program id, which is Microsoft.Windows.Shell.RunDialog. However, I can't get this working with the code below. Any idea?
DesiredCapabilities desktopCapabilities = new DesiredCapabilities();
desktopCapabilities.SetCapability("app", "Microsoft.Windows.Shell.RunDialog");
desktopCapabilities.SetCapability("deviceName", "WindowsPC");
desktopCapabilities.SetCapability("platformName", "Windows");
session = new WindowsDriver<WindowsElement>(new Uri("http://127.0.0.1:4723"), desktopCapabilities);
Take a look at the answers from this post about the run dialog. My best guess is that winappdriver is calling rundll32.exe and that's not the dialog itself.
You could try your luck changing this line
desktopCapabilities.SetCapability("app", "Microsoft.Windows.Shell.RunDialog");
into
desktopCapabilities.SetCapability("app", "c:\windows\system32\rundll32.exe shell32.dll,#61");
Alternatively, you could get the desktop session and send "windows key + r" to it. Here is how you can get the desktop session.
I have an MFC app (10 year old app), which has context sensitive help for each dialog. I want to add help on a specific combobox, as well as a little question mark button next to this control. Users can either select the combobox and hit F1, or they can click on the button next to the combobox, and it will jump to a help page that is specifically about this combobox, rather than general help for the whole dialog.
In the dialog resource properties, I have set "Context Help" to True.
In the combobox properties, I've set "Help ID" to True.
In myapp.hpp, I have added "HIDC_MYCOMBOBOX = mycombobox_help.htm" to the [ALIAS] section, and included the resource.hm file in the [MAP] section.
Again in app.hpp file, the dialog uses "HIDD_MYDIALOG =
mydialog_help.htm"
Yet selecting the combobox and pressing F1 still brings up mydialog_help.htm, instead of mycombobox.htm.
What am I missing to use a separate help page for the control?
Is it possible to redirect the control to an anchor in the main page? Something, along the lines of...
HIDC_MYCOMBOBOX = mydialog_help.htm#mycombobox
I have added a "?" button to run the following code, but this also doesn't give the context for the control, and just opens the mydialog_help.htm.
HELPINFO lhelpinfo;
lhelpinfo.cbSize = sizeof(lhelpinfo);
lhelpinfo.iContextType = HELPINFO_WINDOW;
lhelpinfo.iCtrlId = IDC_BALANCING_METHOD;
lhelpinfo.hItemHandle = GetDlgItem(IDC_BALANCING_METHOD)->m_hWnd;
lhelpinfo.dwContextId = HIDC_BALANCING_METHOD;
lhelpinfo.MousePos = POINT();
CDialog::OnHelpInfo(&lhelpinfo);
I'm trying to add search and replace functionality to a TSynEdit component in a Lazarus project and I'm making use of TSynEdit.SearchReplace(), TFindDialog and TReplaceDialog.
All seems to be working as I need it, pretty much, except that I can't find a way of determining whether the 'Replace' or the 'Replace All' button was clicked on the replace dialog.
I have written the code for the OnFind event and for the OnReplace event but there doesn't seem to be an OnReplaceAll event.
Looking at the auto-help popup for the TReplaceDialog item I can't see any property or other that would allow me to determine which of the buttons had been pressed.
Can anyone point me in the right direction?
Thanks,
FM
In the OnReplace event, check to see if frReplaceAll is in the Options:
procedure TForm1.ReplaceDialog1Replace(Sender: TObject);
begin
with Sender as TReplaceDialog do
begin
if frReplace in Options then
DoReplace(ReplaceDialog1.FindText, ReplaceDialog1.ReplaceText)
else if frReplaceAll in Options then
DoReplaceAll(ReplaceDialog1.FindText, ReplaceDialog1.ReplaceText);
end;
end;
This example is from the Delphi XE 4 documentation, but the dialog should have the same basic implementation detail.