Start firefox from a terminal window, open a text file and position the text shown at a specified line - firefox

I would like to improve the help facility in a Fortran program by opening the user guide in a separate browser (Firefox) window whenever the user type a ?
as answer to a question the program asks.
I can use call system('path/firefox -file user_guide.hlp')
to open the help file. But additionally I would like to position the text in the browser window at a specified line in the help text.
I know which lines in the help file that should be relevant for the user because inside the Fortran program I keep track of the commands the user has made (I use a command line interface, no GUI). At present I print these lines in the terminal window running the program but this limits the amount of lines I can print and obscures the program output. With the whole user guide available in a separate window the user may also easily search for additional explanations elsewhere in the user guide, I do not expect he or she will voluntarily read the user guide.
Thanks for any help
Bo Sundman

You cannot go to specific lines but you could try using named anchor tabs. In the help file,
<a name="1"/>
help topic 1
<a name="2"/>
help topic 2
When you issue your call to firefox, to go to anchor 2
system('path/firefox -file user_guide.html#2')
This should work on all browsers. The newer ones will also take id= instead of name=
EDIT
If the above doesn't work, try
system('path/firefox "file://path/user_guide.html#2"')
EDIT 2
If both the firefox path and html file path have spaces, on Windows, 8.3 filenames can be used. Use dir/x to find out what the 8.3 filenames are. Alternatively filenames with spaces can be used; the syntax is pretty weird
call execute_command_line('""C:\...\firefox.exe" "file://x:\...\userguide.html#2""')
start string with '
Use 2 double quotes for the first double quote ""
Add your pathname to firefox
Use 1 double quote to terminate the path name
add a space
Use 1 double quote to start the parameter
Add the parameter
Use 2 double quotes to terminate
end the string with '

Related

Take X Symbols After a Marker and Save to Variable in AppleScript

I'm looking for a way via AppleScript to take 11 symbols after ?v= part in an URL that's in clipboard and save them into a variable. Here's an example of a link:
https://www.youtube.com/watch?v=PxDK95Q5qN0&ab_channel=TheLateShowwithStephenColbert
So I need a little script that would take a link in clipboard, identify 11 symbols after ?v=, take those 11 symbols (PxDK95Q5qN0) from that link and save it into a variable (e.g. extract).
I did find a partial solution here — but that one only works when it's BETWEEN two parts e.g. ?v= and &. The problem with that solution is that many links are short and do not have the last & symbol (e.g. https://www.youtube.com/watch?v=PxDK95Q5qN0)
I'd appreciate any help or pointers here! :]
Whether you set the clipboard to, e.g.,:
set the clipboard to "https://www.youtube.com/watch?v=PxDK95Q5qN0&ab_channel=TheLateShowwithStephenColbert"
Or, e.g.,:
set the clipboard to "https://www.youtube.com/watch?v=PxDK95Q5qNO"
The following example AppleScript code returns the eleven characters after ?v=:
set extract to do shell script ¬
"sed -Ee 's/.*[?]v[=]([a-zA-Z0-9_-]{11}).*/\\1/'<<<" & ¬
(the clipboard as text)'s quoted form
Note that \\?v\\= can be used instead of the [?]v[=] portion of the sed command as in either case the ? and = are treated as regular characters instead of shell special characters.
Additionally, if the number of target characters changes from 11 yet ?v= and & are still in play, as in your examples, then this regex, with explanation shown further below, handles it:
.*[?]v[=]([a-zA-Z0-9_-]+[^&]).*
Notes:
If the 11 target characters contain other than what is shown in the capturing group:
([a-zA-Z0-9_-]{11})
Then modify it as needed.
Using info from https://regex101.com to explain the regex used in the sed command:
The main part of interest is the Capturing Group ([a-zA-Z0-9_-]{11}), as this is what's returned, if it exists directly after ?v= in the URL.
When Capturing Group is: ([a-zA-Z0-9_-]+)
That macsripter link points you in the right direction (though it's a lot of information to digest). As long as you're running 10.6 or later, you can use this routine:
on getTheV(link_text)
set {tid, my text item delimiters} to {my text item delimiters, {"=", "&"}}
set theV to second text item of link_text
set my text item delimiters to tid
return theV
end getTheV
which breaks the link up into text items — split on '=' and '&' — and returns the second item.
Use it like so:
set theV to getTheV("http://...")
Both the links you provided return the correct value.

Win 10: Desktop.ini infotip/tooltip text formatting - line break

I'm trying to customize some folders in Windows 10 os using Desktop.ini text files. One thing I can't solve is how to make a line break in the infotip.
Current text file looks like this:
[.ShellClassInfo]
ConfirmFileOp=0
NoSharing=1
IconFile=$path_to_icon
IconIndex=0
InfoTip=Line1 \n Line2
So the last line of the text document is not working as desired. It just doesn't recognize the \n symbol. I also tried replacing the standard \n new line symbol with unicode characters and some other similar methods and symbols, but it didn't work. It just recognizes it as a string no matter what is written there.
The only way I could achieve a line break was to add so many characters, that Win 10 would automatically start a new line.
Help is much appreciated. Thank you!
You could define a string in a resource-only DLL:
InfoTip=#Your.dll,-12345
The negative number defines the resource ID of the string to use.
String resources in a DLL are not limited in the range of character codes, so this should in principle enable you to use line breaks (ASCII code 10).
To create such a resource-only DLL there are many free tools available, google for "windows resource editor".

bash: how to make a clickable link with query parameters?

I am trying to dump url on the terminal that needs to be clickable, and the url comes with a query parameter. For example --
google='https://www.google.com/search?q='
orgname='foo bar'
gsearch=$google\'$orgname\'
echo "details: $orgname ($gsearch)"
But the problem is that the clickable link totally omits everything after the q=, i.e. does not include the string 'foo bar', please see the image below --
How do I make a clickable link that includes the query (i.e. the whole url in the braces above)?
Please also note that I am adding quote in the search parameter since the it may contain spaces.
Single quotes are not valid in URLs. Use the URL encoding %27 instead:
google='https://www.google.com/search?q='
orgname='foo'
gsearch=$google%27$orgname%27
echo "details: $orgname ($gsearch)"
Note that it's the terminal and not your script that decides what's considered part of a URL for the purpose of selecting or clicking. The above results in
https://www.google.com/search?q=%27foo%27
which is more clickable in most terminals. The script can't specify what's the extent of the URL except through expressing it in such a standard way that each individual terminal emulator has a decent chance of recognizing it.
PS: I don't think Google cares about surrounding single quotes.

jsch shell select a menu option

I am experiencing an issue with my program where when I hit a certain menu I am unable to enter in an option. The menu looks like a prompt with a pre-selected option where one is able to change the option by over writing it.
Here is what it looks like:
As you can see 3 is already selected. I simply want to over write it and enter in another option.
When I simply try to write an option to it and print out what the shell it it gives me this when I do a system.out.println:
set encryption home
Wireless Encryption Type:[0] quit, [1] OPEN, [2] WEP, or [3] WPA
Wireless Encryption Type: 31
It will simply do option 3 and ignor the "1" and will read the "\r\n" I have in the command I sent (which was "1\r\n"). In between there is a character which is not represented here it is character 0x08. How can I get my program to overwrite the default option?
Things I have tried:
I have tried doing \n\r
semicolon ;
\n\r before the command
\r
ommiting \r\n (this causes the program to never go past the wireless encryption type because it did not enter anything).
I have no idea what to do next with this. Any ideas?
ps: I am using a pipedinput to enter in all of the commands as suggested by nilbot
found the problem, the shell did not like the /n/r and counted each one as an enter. so it works once i removed either the /r or the /n. currently I have it at /n, hope this helps someone!

Is there a way to delete all comments in a file using Notepad++?

Notepad++ obviously recognizes all comments as such. Is there a way to simply delete all?
Edit: Stat-R's bookmark method has helped greatly, not only for removing comments but for conditionally removing lines in general.
For a general file, first of all you need to know the comment operator of the language you are writing the file in. For example, in java script the comment operator is //.
For the following code...
In NP++, you need to
Mark the lines that contains '//'. Make sure the bookmark option is enabled.
Then, choose from NP++ menu Search>Bookmark>Remove Bookmarked lines
EDIT:
Another solution after #Chris Mirno 's suggestion is as follows:
Use regular expression. See the image below. It is self explanatory
To understand it better, refer to these
In the Find & Replace Dialog, put the following regex and adjust the search options as depicted.
/\*.*?\*/
Replace with: (empty)
Select Mode: Regular Expression AND .(dot) matches newline
This should remove all your C style comments spanned across lines.
Star-R and Chris Mirno Answer are also Correct and Good.
But For Line Comment:
//.*?(?=\r?$)
Explanation:
// will be the Starting Position
.*? Will be any character
(?=\r?$) will search to the end of the line (as it is required in line comment)
Note:
But Still check each of the line because for example if your code contains soap format like
//www.w3.org/2001/XMLSchema-instance\x2......");
it will capture this line because the starting is // and it goes to end of the line so watch out for this :)
Warning to all using Stat-R's solution:
This method will remove lines of code if formatted like this:
echo "hello"; //This comment will be detected
Following his method, the entire line will be removed.
Therefore make sure to go through and make these comments, their own line before doing this method.
I have had some luck running a macro for the above. Basically:
search for // (F3)
select to end of line (shift+end)
delete (delete)
Put // into the search dialog by just searching for it once. Then record the three steps in a macro, then play it back until EOF.
The first time I did it I had a problem, but then it worked, not sure what I did differently.
Anton Largiader's answer was the most reliable one, including complex inline comments.
However, it will leave many empty lines, including ones with empty characters (space, tabs...) so I would just add another step to make it almost perfect:
After running the macro, just do:
Edit > Line Operations > Remove Empty Lines
OR
Edit > Line Operations > Remove Empty Lines (Containing Blank Characters)
1st option is good if you wish to remove only really empty lines
2nd options will remove every empty line even containing space etc. so there will be no more actual spacing left between code blocks. 1st option might be the safest with some manual cleanup afterwards.
As someone suggested in another post, the simplest and most reliable is maybe to export the all text in .RTF format using Menu Plugin-->NppExport-->Export to RTF and then:
-Open the newly created file in Word
-Select any part of any comment
-On the top-right side of Word clic Select--> Select all texts with similar formatting
-Remove the selected comments all at once (del or cut if doesn't work)
To remove Powershell comments if someone find it handy:
Removing Comment in a Powershell using Notepad ++
To find just lines beginning with # (and not with # elsewhere in the line).
Notepad++ SEARCH Menu > Find
‘Mark‘ Tab – fill in as below.
Select ‘Mark All’ (clear all marks if used previously).
Regex ^[#}
enter image description here
SEARCH Menu > bookmark > Remove (or do anything on the list with
them)
Clear all marks to reset
You can select no comments just code by doing the following:
Regex ^[^#}
enter image description here
Enter ctrl+shift+K to remove comment

Resources