Command line option and skip page - command-line

I am creating a setup using NSIS which include some builtin pages and some custom page also.In that i want to show a custom page using install only if a command line is passed during install.How it can be done?
Example
!include "MUI.nsh"
!include nsDialogs.nsh
OutFile "myCustomPage.exe"
var installmethod
Page Custom MyCustomPage
Page Custom MyCustomPage1
Page Custom MyCustomPage3
Function MyCustomPage
nsDialogs::Create 1044
nsDialogs::Show
FunctionEnd
Function MyCustomPage1
nsDialogs::Create 1044
nsDialogs::Show
FunctionEnd
Function MyCustomPage3
nsDialogs::Create 1044
nsDialogs::Show
FunctionEnd
Section Dummy
SectionEnd
In the above example i have 3 pages.I want to shown only two pages MyCustomPage and MyCustomPage3 during normal install. If a command line(specif command line) passed then all 3 pages should appear during installation.how it can be done?

!include FileFunc.nsh
!include LogicLib.nsh
Page Custom MyPageCreate
Function MyPageCreate
${GetParameters} $0
ClearErrors
${GetOptions} "$0" "/ShowSpecial" $1
${If} ${Errors}
Abort ; Skip page
${EndIf}
nsDialogs::Create 1044
nsDialogs::Show
FunctionEnd

Below code skips page MyCustomPage1 if the command line option is "a".
!include "MUI.nsh"
!include "FileFunc.nsh"
!include nsDialogs.nsh
!insertmacro GetParameters
OutFile "myCustomPage.exe"
var installmethod
Page Custom MyCustomPage
Page Custom MyCustomPage1
Page Custom MyCustomPage3
Function MyCustomPage
nsDialogs::Create 1044
nsDialogs::Show
FunctionEnd
Function MyCustomPage1
${GetParameters} $R0
${If} $R0 == 'a'
abort
${EndIf}
nsDialogs::Create 1044
nsDialogs::Show
FunctionEnd
Function MyCustomPage3
nsDialogs::Create 1044
nsDialogs::Show
FunctionEnd
Section Dummy
SectionEnd

Related

"Send %variable%" evals my variable before sending it

I have an autohotkey script(A) that write another script(B).
The important line in my script(A):
InputBox variable, Variable
Send %variable%
Then, if i input:
helloworld{enter}
it will write "helloworld" and insert a new line in my script(B) instead of just writing "{enter}"
How do I force it to write %variable% without interpreting it beforehand ?
I agree with the other answer that using FileAppend would be a better method. However, if you truly want to accomplish this using the send command, then you need to use {raw} mode. You can read about {raw} in the documentation:
https://autohotkey.com/docs/commands/Send.htm
InputBox variable, Variable
Send, {raw}%variable%
The simplest way to write another script (scriptB) from scriptA is to use FileAppend:
variable = helloworld
FileAppend,
(
; a line of code
Send %variable%{enter}
; another line of code
)
,C:\scriptB.ahk
Run, edit "C:\scriptB.ahk"
; or:
; Run, C:\scriptB.ahk
or
InputBox variable, Variable, Enter a variable:
if not ErrorLevel
{
FileAppend,
(
; a line of code
Send %variable%{enter}
; another line of code
)
,C:\scriptB.ahk
Run, edit "C:\scriptB.ahk"
; or:
; Run C:\scriptB.ahk
}
return

NSIS: Maximize/Minimize Button event Handling

I want to know how can I handle the event when I click the maximize button(I have enabled it already) of my nsis dialog.
I want to perform some other dialog element resizing every time I click maximize button, and restore when its minimized.
So, how can I achieve it???
Please help.
Thanks in advance.
NSIS was really not designed to handle re-sizable dialogs.
The only way to catch a size event would be to use a plugin. You could write your own custom plugin or try the experimental WndSubclass plugin, either way you pretty much need to know a bit about the Windows API to do this...
Edit:
!include nsDialogs.nsh
!include WinCore.nsh
!include WndSubclass.nsh
!macro _Win_HIWORD_FIXED _outvar _in
IntOp ${_outvar} "${_in}" >> 16 ;sign extended
${LOWORD} ${_outvar} ${_outvar} ;make sure we strip off the upper word
!macroend
!undef HIWORD
!define HIWORD "!insertmacro _Win_HIWORD_FIXED "
Var ParentSubProc
Function ParentSubProc
${If} $2 = ${WM_SIZE}
${LOWORD} $1 $4
${HIWORD} $2 $4
${NSD_SetText} $hwndparent "Size: $1 x $2"
${EndIf}
FunctionEnd
Function .onGuiInit
${NSD_AddStyle} $hwndparent 0x70000
${WndSubclass_Subclass} $hwndparent ParentSubProc $ParentSubProc $ParentSubProc
FunctionEnd

substitution within a text file, using Applescript and sed

The question is a sequel to plain text URL to HTML code (Automator/AppleScript).
Suppose I have a plain txt file /Users/myname/Desktop/URLlist.txt:
title 1
http://a.b/c
title 2
http://d.e/f
...
I'd like to (1) convert all the URL (http://...) to HTML code, and (2) add
<br />
to each empty line, so that the aforementioned content will become:
title 1
http://a.b/c
<br />
title 2
http://d.e/f
<br />
...
I come to the following Applescript:
set inFile to "/Users/myname/Desktop/URLlist.txt"
set middleFile to "/Users/myname/Desktop/URLlist2.txt"
set outFile to "/Users/myname/Desktop/URLlist3.txt"
do shell script "sed 's/\\(http[^ ]*\\)/<a href=\"\\1\">\\1<\\/a>/g' " & quoted form of inFile & " >" & quoted form of middleFile
do shell script "sed 's/^$/\\ <br \\/>/g' " & quoted form of middleFile & " >" & quoted form of outFile
It works, but it is redundant (and silly?). Could anyone make it more succinct? Can it be done involving only one text file instead of three (i.e. the original content in /Users/myname/Desktop/URLlist.txt is overwritten with the end result)?
Thank you very much in advance.
Try:
set inFile to "/Users/myname/Desktop/URLlist.txt"
set myData to (do shell script "sed '
/\\(http[^ ]*\\)/ a\\
<br />
' " & quoted form of inFile & " | sed 's/\\(http[^ ]*\\)/<a href=\"\\1\">\\1<\\/a>/g' ")
do shell script "echo " & quoted form of myData & " > " & quoted form of inFile
This will let you use the myData variable later in your script. If this is not part of a larger script and you are simply modifying your file, use the -i option as jackjr300 suggests. Also, this script looks for the original pattern and appends the new line to it rather than simply looking for empty lines.
EDIT:
set inFile to "/Users/myname/Desktop/URLlist.txt"
set myData to (do shell script "sed 's/\\(http[^ ]*\\)/<a href=\"\\1\">\\1<\\/a>/g; s/^$/\\ <br \\/>/g' " & quoted form of inFile)
do shell script "echo " & quoted form of myData & " > " & quoted form of inFile
Use the -i '' option to edit files in-place.
set inFile to "/Users/myname/Desktop/URLlist.txt"
do shell script "sed -i '' 's:^$:\\ <br />:; s:\\(http[^ ]*\\):\\1:g' " & quoted form of inFile
If you want a copy of the original file, use a specified extension like sed -i ' copy'
--
Updated:
A `DOCTYPE is a required preamble.
DOCTYPEs are required for legacy reasons. When omitted, browsers tend to use a different rendering mode that is incompatible with some specifications. Including the DOCTYPE in a document ensures that the browser makes a best-effort attempt at following the relevant specifications.
The HTML lang attribute can be used to declare the language of a Web page or a portion of a Web page. This is meant to assist search engines and browsers. According to the W3C recommendation you should declare the primary language for each Web page with the lang attribute inside the <html> tag
The <meta> tag provides metadata about the HTML document. <meta> tags always goes inside the <head> element.
The http-equiv attribute provides an HTTP header for the information/value of the content attribute.
content: the value associated with the http-equiv or name attribute.
charset: To display an HTML page correctly, the browser must know what character-set to use.
In this script: I put "utf-8" as encoding, change it by the encoding of your original file.
set inFile to "/Users/myname/Desktop/URLlist.html" -- text file with a ".html" extension
set nL to linefeed
set prepandHTML to "<!DOCTYPE html>\\" & nL & "<html xmlns=\"http://www.w3.org/1999/xhtml\" xml:lang=\"en-US\" lang=\"en-US\">\\" & nL & tab & "<head><meta http-equiv=\"content-type\" content=\"text/html; charset=utf-8\" />\\" & nL & "</head>\\" & nL
do shell script "sed -i '' 's:^$:\\ <br />:; s:\\(http[^ ]*\\):\\1:g; 1s~^~" & prepandHTML & "~' " & quoted form of inFile
do shell script "echo '</html>' " & quoted form of inFile -- write last HTML tag
I can't understand sed commands very well (it makes my brain hurt) so here's the applescript way to do this task. Hope it helps.
set f to (path to desktop as text) & "URLlist.txt"
set emptyLine to " <br />"
set htmlLine1 to "<a href=\""
set htmlLine2 to "\">"
set htmlLine3 to "</a>"
-- read the file into a list
set fileList to paragraphs of (read file f)
-- modify the file as required into a new list
set newList to {}
repeat with i from 1 to count of fileList
set thisItem to item i of fileList
if thisItem is "" then
set end of newList to emptyLine
else if thisItem starts with "http" then
set end of newList to htmlLine1 & thisItem & htmlLine2 & thisItem & htmlLine3
else
set end of newList to thisItem
end if
end repeat
-- make the new list into a string
set text item delimiters to return
set newFile to newList as text
set text item delimiters to ""
-- write the new string back to the file overwriting its contents
set openFile to open for access file f with write permission
write newFile to openFile starting at 0 as text
close access openFile
EDIT: if you have trouble with the encoding these 2 handlers will handle the read/write properly. So just insert them in the code and adjust those lines to use the handlers. Good luck.
NOTE: when opening the file using TextEdit, use the File menu and open specifically as UTF-8.
on writeTo_UTF8(targetFile, theText, appendText)
try
set targetFile to targetFile as text
set openFile to open for access file targetFile with write permission
if appendText is false then
set eof of openFile to 0
write «data rdatEFBBBF» to openFile starting at eof -- UTF-8 BOM
else
tell application "Finder" to set fileExists to exists file targetFile
if fileExists is false then
set eof of openFile to 0
write «data rdatEFBBBF» to openFile starting at eof -- UTF-8 BOM
end if
end if
write theText as «class utf8» to openFile starting at eof
close access openFile
return true
on error theError
try
close access file targetFile
end try
return theError
end try
end writeTo_UTF8
on readFrom_UTF8(targetFile)
try
set targetFile to targetFile as text
targetFile as alias -- if file doesn't exist then you get an error
set openFile to open for access file targetFile
set theText to read openFile as «class utf8»
close access openFile
return theText
on error
try
close access file targetFile
end try
return false
end try
end readFrom_UTF8

How to do escaping in this Perl code?

#!/usr/bin/perl
use warnings;
system ("dialog --menu Customize 10 70 50 'Flush rules' 'Clear all the rules' 'Show rules' 'Shows the current rules' 2> /tmp/tmp.txt ")
I want to write the above code in a more readable form like this
#!/usr/bin/perl
use warnings;
system ("dialog --menu Customize 10 70 50
'Flush rules' 'Clear all the rules'
'Show rules' 'Shows the current rules'
'more options' '........' 2> /tmp/tmp.txt ")
How can I do this?
Perl provides a string concatentation operator that you can use to build up big strings:
system ( "dialog --menu Customize 10 70 50 "
. "'Flush rules' 'Clear all the rules' "
. "'Show rules' 'Shows the current rules' "
. "'more options' '........' 2> /tmp/tmp.txt ");
system can take #args (array form):
system ( 'dialog', #args );
system ( "dialog --menu Customize 10 70 50 "
. "'Flush rules' 'Clear all the rules' "
. "'Show rules' 'Shows the current rules' "
. "'more options' '........' 2> /tmp/tmp.txt ");
Dang, tadmc is fast. Yes, use the . concatenation command.
I would recommend that you create your command in a separate string and then execute that. I also recommend using the qq command to do quoting. That way, you don't have to worry about single vs. double quotes:
my $command = qq(dialog --menu Customize 10 70 50 )
. qq("Flush rules" 'Clear all the rules' )
. qq('Show rules' 'Shows the current rules' )
. qq'more options' '........' 2> /tmp/temp.$$ );
my $error = system $command;
Using qq allows you not to worry about whether I need to use double quotes to allow for variable interpolation or single quotes, or having to escape quotes. For example, I was able to mix double and single quotes, and I can use Perl variables without worrying whether or not I have to change from single to double quotes. For example, I use /tmp/temp.$$. The $$ is the process ID, so if this command is executed twice, there are two different temp files used.
By creating a separate variable for my command, I can now use it later -- like if there was an error in my system command.
By the way, you should always check the return of your system command. There's probably a good chance that if for some reason you can't execute your system command, you probably want to error out or at least note the issue.
One of the problems is that the output of the system command is the opposite of most Perl functions. In most Perl functions, a return of zero indicates a failure while a return of non-zero indicates success. However, the system function is the exact opposite. Zero means success, non-Zero means failure.
That can lead to strange if constructs:
if (system $command) {
die qq(Can't execute command "$command"\n);
};
This looks like I'm saying that if my system command succeeds, I should die, but it really means the same as this:
my $error = system $command;
if ($error) {
die qq(Can't execute command "$command"\n);
}
That syntactically makes a lot more sense.

Vimperator pass-through/unset <C-Tab> by default

By default is mapped to gt command, which selects next tab. I want to pass-through to Crtl+Tab plugin which does MRU for tabs.
Any idea?
Since you want to pass-through, use:
:map <C-Tab> i<C-Tab>
you can map C-Tab to gt command and, maybe, Control-Shift-Tab to gT command.
:inoremap <C-Tab> gt
:inoremap <C-S-Tab> gT
save your vimperatorrc with :mkvimperatorrc!
1) Use pentadactyl instead of vimperator. (pentadactyl is a fork of vimperator)
2) put in ~/_pentadactylrc the following:
nm <C-Tab> <Pass>
nm <C-S-Tab> <Pass>
Then pentadactyl will pass these events directly to Firefox.