Remember check box state when click back during NSIS installer - checkbox

I have a checkbox on one of my customer installer pages
${NSD_CreateCheckbox} 0 0 100% 15 "Check to run"
Pop $SvcCheckBox
CreateFont $0 "$(^Font)" "10"
SendMessage $SvcCheckBox ${WM_SETFONT} $0 1
GetFunctionAddress $0 OnCheckbox
nsDialogs::OnClick $SvcCheckBox $0
I want to remember this if the user comes back to this page.
I've used the code below to attempt this
${NSD_OnBack} "pageLeave"
FunctionEnd
Function pageLeave
${NSD_GetState} $SvcCheckBoxState $SvcCheckBox
FunctionEnd
However, if a user un-checks the box, goes to the next page, comes back to this page, the check box is checked again. I need it to remain unchecked.
How do I implement my pageLeave check box state on page load?

You need initialize the checkbox state when you create the page. You don't need a On* handler unless you want to update something else on the page when the checkbox changes.
!include nsDialogs.nsh
Var CheckboxState
Var hCheckbox
Function .onInit
StrCpy $CheckboxState ${BST_CHECKED} ; Set initial/default state
FunctionEnd
Page Components
Page Custom MyPageCreate MyPageLeave
Page Components
Page InstFiles
Function MyPageCreate
nsDialogs::Create 1018
Pop $0
${NSD_CreateCheckbox} 0 0 100% 15 "Check to run"
Pop $hCheckbox
${NSD_SetState} $hCheckbox $CheckboxState
nsDialogs::Show
FunctionEnd
Function MyPageLeave
${NSD_GetState} $hCheckbox $CheckboxState
FunctionEnd
Section
DetailPrint State=$CheckboxState
SectionEnd

Related

Pause in the middle of a Clojure doseq function?

My program allows users to select files to import into a database. Before now, it only allowed them to import one file at a time. Letting them import more than one file at a time is easy. But the problem I have is that if the database already contains a page with the same title, I want to display a warning and get confirmation before overwriting the version in the database with the one being imported.
Here's what I have so far. It largely follows what I was doing to import single files.
;; Handler for the POST "/import" route.
(defn- post-import-page
"Import the file(s) specified in the upload dialog. Checks the page
title of the import file against existing pages in the database. If
a page of the same name already exists, asks for confirmation before
importing."
[{{file-info "file-info"
referer "referer"} :multipart-params :as req}]
(let [file-vec (if (map? file-info)
(conj [] file-info)
file-info)]
(doseq [fm file-vec]
(let [file-name (:filename fm)
import-map (files/load-markdown-from-file (:tempfile fm))
page-title (get-in import-map [:meta :title])
id-exists? (db/title->page-id page-title)]
(if id-exists?
(build-response
(layout/compose-import-existing-page-warning
import-map file-name referer) req)
(do-the-import import-map file-name req))))))
This function imports any files that don't already exist in the database, but doesn't import anything that would overwrite an existing database entry with the same title. It never shows the warning page asking for confirmation either.
The warning page is constructed like this:
(defn compose-import-existing-page-warning
"Return a page stating that a page with the same title already exists
in the wiki. Ask the user to proceed or cancel the import."
[import-map file-name referer]
(short-form-template
[:div {:class "cwiki-form"}
(form-to {:enctype "multipart/form-data"
:autocomplete "off"}
[:post "proceed-with-import"]
(hidden-field "import-map" import-map)
(hidden-field "file-name" file-name)
(hidden-field "referer" referer)
[:p {:class "form-title"} "Page Already Exists"]
[:div {:class "form-group"}
[:p (str "A page with the title \"" (get-in import-map [:meta :title])
"\" already exists in the wiki.")]
[:p (str "Click \"Proceed\" to delete the existing page and "
"replace it with the contents of the imported file.")]
[:div {:class "button-bar-container"}
(submit-button {:id "proceed-with-import-button"
:class "form-button button-bar-item"}
"Proceed")
[:input {:type "button" :name "cancel-button"
:value "Cancel"
:class "form-button button-bar-item"
:autofocus "autofocus"
:onclick "window.history.back();"}]]])]))
How would the program be paused in the middle of the doseq (or other looping function) to display the confirmation page and wait for the user to make a selection?
Just use read-line in the middle of your loop, and then an if to choose the branching you want. Here is a list of other documentation you may find useful, especially the Clojure CheatSheet.

Im Trying to get Apple Script to Read A file and tell me if certain key words are in there

I've gotten this far but I don't know what to do next if you know.
Can you please make edits to the script and then post the script back?
on TerrorChecker()
tell application "Finder"
read ("/ Users / BenEvans / desktop / Test")
if "Blue,Red,Yellow" then display dialog "Terror Alert" buttons {"OK"} default button 1
end tell
do
Nothing
end TerrorChecker
TerrorChecker()
end TerrorChecker
assumed there's a file contains the keyword "darkness", try this one:
set fileContent to (read (choose file))
if "darkness" is in fileContent then
display dialog "terror alert" buttons {"OK"} default button 1
else
say "no keyword found"
end if
btw, the command read cannot handle property file, e.g. *.pdf, *.xls
then try this one:
set fileContent to (read (choose file))
if "blue" is in fileContent then
display dialog "terror alert" buttons {"OK"} default button 1
else if "red" is in fileContent then
display dialog "terror alert" buttons {"OK"} default button 1
else if "yellow" is in fileContent then
display dialog "terror alert" buttons {"OK"} default button 1
else
say "no keyword found"
end if
Your example was a little bit of a mess, so I've modified it below.
on run
TerrorChecker()
end run
on TerrorChecker()
tell application "Finder"
set theData to read "/Users/BenEvans/Desktop/Test"
if theData contains "Blue,Red,Yellow" then
display dialog "Terror Alert" buttons {"OK"} default button 1
end if
end tell
end TerrorChecker

NSIS license page prechecked

I have the following code in an NSIS script...
!define MUI_LICENSEPAGE_CHECKBOX
!insertmacro MUI_PAGE_LICENSE "eula.txt"
... and it works fine. As expected, the user needs to check the "I accept..." checkbox and then the install button is enabled.
I would like to simplify the process so that the checkbox is checked and the install button enabled by default and all the user needs to do is install or cancel.
Thank you all.
!define MUI_LICENSEPAGE_CHECKBOX ; Tell MUI you want the checkbox version of the license page
!define MUI_PAGE_CUSTOMFUNCTION_SHOW licshow ; Tell MUI to call a function before the page is displayed
!insertmacro MUI_PAGE_LICENSE "eula.txt" ; Adds the page
Function licshow ; Function to be called before the page is displayed
; Check it
FindWindow $0 "#32770" "" $HWNDPARENT ; Find the inner dialog (See attached picture)
GetDlgItem $0 $0 0x40A ; Find the checkbox control
SendMessage $0 ${BM_SETCHECK} 1 0 ; Check the checkbox
; Enable button
GetDlgItem $0 $hwndparent 1 ; Find the Install/Next button
EnableWindow $0 1 ; Enable the button
FunctionEnd
The last GetDlgItem+EnableWindow commands can be replaced by SendMessage $HWNDPARENT ${WM_COMMAND} 0x40A 0 to simulate the user clicking and would cause NSIS internal processing to enable the button.
I got lucky and was able to throw code together from several places.
The following works but I don't really know why NSIS-wise, which I don't like at all. If someone can break it down, I would really, really, appreciate it.
!define MUI_LICENSEPAGE_CHECKBOX
!define MUI_PAGE_CUSTOMFUNCTION_SHOW licshow
!insertmacro MUI_PAGE_LICENSE "eula.txt"
Function licshow
; Check it
FindWindow $0 "#32770" "" $HWNDPARENT
GetDlgItem $0 $0 0x40A
SendMessage $0 ${BM_SETCHECK} 1 0
; Enable button
GetDlgItem $0 $hwndparent 1
EnableWindow $0 1
FunctionEnd

Clicking checkbox on web page using Applescript

I'm somewhat new to Applescript, and I am trying to make Applescript check a checkbox to select it. I want the checkbox to be clicked regardless of whether or not it's already checked. Here is the checkbox's location according to the Accessibility Inspector:
<AXApplication: “Safari”>
<AXWindow: “Studio”>
<AXGroup>
<AXGroup>
<AXGroup>
<AXScrollArea: “”>
<AXWebArea: “”>
<AXGroup: “”>
<AXCheckBox: “”>
Attributes:
AXRole: “AXCheckBox”
AXSubrole: “(null)”
AXRoleDescription: “check box”
AXChildren: “<array of size 0>”
AXHelp: “”
AXParent: “<AXGroup: “”>”
AXPosition: “x=1104 y=825”
AXSize: “w=18 h=19”
AXTitle: “”
AXDescription: “”
AXValue: “0”
AXFocused (W): “0”
AXEnabled: “1”
AXWindow: “<AXWindow: “Studio”>”
AXSelectedTextMarkerRange (W): “<AXTextMarkerRange 0x101937860 [0x7fff76e43fa0]>{startMarker:<AXTextMarker 0x1019378b0 [0x7fff76e43fa0]>{length = 24, bytes = 0xac01000000000000c0366e23010000001700000001000000} endMarker:<AXTextMarker 0x101938030 [0x7fff76e43fa0]>{length = 24, bytes = 0xac01000000000000c0366e23010000001700000001000000}}”
AXStartTextMarker: “<AXTextMarker 0x101938030 [0x7fff76e43fa0]>{length = 24, bytes = 0xa00000000000000098975e0d010000000000000001000000}”
AXEndTextMarker: “<AXTextMarker 0x1019378b0 [0x7fff76e43fa0]>{length = 24, bytes = 0xa200000000000000405e7812010000000000000001000000}”
AXVisited: “0”
AXLinkedUIElements: “(null)”
AXSelected: “0”
AXBlockQuoteLevel: “0”
AXTopLevelUIElement: “<AXWindow: “Studio”>”
AXTitleUIElement: “(null)”
AXAccessKey: “(null)”
AXRequired: “0”
AXInvalid: “false”
AXARIABusy: “0”
Actions:
AXPress - press
AXShowMenu - show menu
I've tried multiple methods to get this to work, and I haven't been able to. Any help is appreciated.
Your question with the Accessibility Inspector info is not very helpful I am afraid.
It would help if we could see the actual elements of the web page,
Have a look at this page which I found that shows check boxes and the code that makes it up.
Each element has a name and maybe within some other element.
on the page I can use this Applescript/Javascript to check the check1 checkbox.
Hopefully this will give you an idea of how to go about it.
But remember this code snippet is tailored to this page.
Open the web page and run this applescript
tell application "Safari"
set doc to document 1
do JavaScript "document.forms['testform']['check1'].checked = true" in doc
end tell
Update: Applescript GUI
Update:2 take into account "clicked regardless of whether or not it's already checked"
Taking a punt with your Accessibility Inspector. Which is a bit useless (not your fault)
try:
activate application "Safari"
tell application "System Events"
set theCheckbox to (checkbox 1 of group 3 of UI element 1 of scroll area 1 of group 1 of group 1 of group 2 of window 1 of application process "Safari")
set isEnabled to value of theCheckbox as boolean
if not isEnabled then
click theCheckbox
end if
end tell

Problems on creating new page in NSIS with checkbox etc

I want to insert a new page in the installation which contains two checkboxes named Client version and Server version. On clicking client version nothing special happens as of now. But if server version is selected then a browse option should come to select a folder (This is not a installation folder). I am finding some difficulties to do this. I have added two checkboxes, a text box and browse button. In the onchange of checkbox I make browse and textbox.
But now the problem is
I want only one checkbox to be checked at a time.
When server version checked browse option should appear (which works now), but if it is unchecked again then that browse option should disappear (which does not work because I was not able to write code for that).
If I click Next on this page and then come back to same page using Back then all controls or checkbox I checked should be as it is. But now those browse options will disappear even if server version checkbox is selected (as I have not done proper coding for this also).
So please help me to do all these things. Also help me if there any other method to do the same
!define PRODUCT_NAME "My application"
!define PRODUCT_VERSION "1.0"
Var Dialog
Var Text
Var Text_State
Var Checkbox
Var Checkbox1
Var Checkbox_State
Var Checkbox1_State
var /GLOBAL SOURCETEXT
var /global SOURCE
var /global BROWSESOURCE
!include "MUI.nsh"
!include nsDialogs.nsh
!define MUI_ABORTWARNING
!define MUI_ICON "${NSISDIR}\Contrib\Graphics\Icons\modern-install.ico"
!define MUI_UNICON "${NSISDIR}\Contrib\Graphics\Icons\modern-uninstall.ico"
!insertmacro MUI_PAGE_WELCOME
!insertmacro MUI_PAGE_DIRECTORY
!insertmacro MUI_PAGE_INSTFILES
!insertmacro MUI_PAGE_FINISH
!insertmacro MUI_UNPAGE_INSTFILES
!insertmacro MUI_LANGUAGE "English"
Page custom InstallPageCreate checkinstdir
Name "${PRODUCT_NAME} ${PRODUCT_VERSION}"
OutFile "Setup.exe"
InstallDir "$PROGRAMFILES\My application"
ShowInstDetails show
ShowUnInstDetails show
Var InstallPageDialog
Var InstallPage.DirRequest
Var InstallPage.BrowseButton
Var mui.WelcomePage
Var mui.WelcomePage1
Var mui.WelcomePage.Image1
Var mui.WelcomePage.Title
Var mui.WelcomePage.Text
Var ImageHandle
Var mui.WelcomePage.Title.Font
Var LINK
Var LINK.Font
Var clickinstall
Var mui.WelcomePage.Image.Bitmap
var checked
var checked1
Var CheckBox.Font
var mui.WelcomePage1.Title1
var mui.WelcomePage.Title.Font1
Function InstallPageCreate
nsDialogs::Create 1044
Pop $mui.WelcomePage
nsDialogs::SetRTL $(^RTL)
SetCtlColors $mui.WelcomePage 0xffffff 0xffffff
${NSD_CreateLabel} 120u 70u 140u 14u "Choose the intallation method"
Pop $clickinstall
SetCtlColors $clickinstall "" "ffffff"
${NSD_CreateCheckbox} 120u 90u 100% 10u "&Client version"
Pop $CheckBox
CreateFont $CheckBox.Font "$(^Font)" "08" "500"
SetCtlColors $CheckBox "" "FFFFFF"
SendMessage $CheckBox ${WM_SETFONT} $CheckBox.Font 0
GetFunctionAddress $0 OnCheckbox1
nsDialogs::OnClick $CheckBox $0
${NSD_CreateCheckbox} 120u 100u 100% 10u "&Server version"
Pop $CheckBox1
CreateFont $CheckBox.Font "$(^Font)" "08" "500"
SetCtlColors $CheckBox1 "" "FFFFFF"
SendMessage $CheckBox1 ${WM_SETFONT} $CheckBox.Font 0
GetFunctionAddress $0 OnCheckbox2
nsDialogs::OnClick $CheckBox1 $0
${If} $Checkbox_State == ${BST_CHECKED}
${NSD_Check} $Checkbox
${EndIf}
${If} $Checkbox1_State == ${BST_CHECKED}
${NSD_Check} $Checkbox1
${EndIf}
nsDialogs::Show
${NSD_FreeImage} $mui.WelcomePage.Image.Bitmap
FunctionEnd
Function OnCheckbox2
StrCpy $SOURCE "C:\"
${NSD_CreateText} 120u 120u 80u 12u "$SOURCE"
pop $SOURCETEXT
${NSD_CreateBrowseButton} 280u 120u 35u 14u "Browse"
Pop $InstallPage.BrowseButton
${NSD_OnClick} $InstallPage.BrowseButton Browsesource
FunctionEnd
Function OnCheckbox1
FunctionEnd
Function checkinstdir
${NSD_GetText} $Text $Text_State
${NSD_GetState} $Checkbox $Checkbox_State
${If} $Checkbox_State == ${BST_CHECKED}
strcpy $checked 1
${else}
strcpy $checked 0
${Endif}
${NSD_GetState} $Checkbox1 $Checkbox1_State
${If} $Checkbox1_State == ${BST_CHECKED}
strcpy $checked1 1
${else}
strcpy $checked1 0
${Endif}
FunctionEnd
Function Browsesource
nsDialogs::SelectFolderDialog "Select Source Folder" "c:\"
pop $SOURCE
${NSD_SetText} $SOURCETEXT $SOURCE
FunctionEnd
Section "MainSection" SEC01
SectionEnd
Section -Post
SectionEnd

Resources