ATTENTION: You are viewing a page formatted for mobile devices; to view the full web page, click HERE.

DonationCoder.com Software > Post New Requests Here

REQ: Convert/Export Certain Browser's "Groups" as Chrome Bookmarks

<< < (3/5) > >>

4wd:
Powershell version, don't know what the minimum version of Powershell it requires is since I'm using v4 (Win 8.1).

It's set to Simplified Chinese input but that can be changed by editing one value or I could change it to use whatever the console is using, (entering a value gives more flexibility I think).  Line 27 in script is where it's set, eg. gb2312 = Simplified Chinese, (PRC).

Double-click the shortcut to run it, (needs to be in same folder as the script unless you edit the shortcut properties).


--- Code: PowerShell ---<#.SYNOPSIS   Converts Green Browser Group files to HTML bookmarks (Mozilla/Chrome).DESCRIPTION   Reads all ANSI .cgp files in a folder according to encoding specified, saves   to temp UTF-8 file, then reads file and outputs to Mozilla/Chrome compatible   bookmark format..PARAMETER <paramName>   None.EXAMPLE   PS> CGP2HTML.ps1#> Function Get-Folder {  Add-Type -AssemblyName System.Windows.Forms  $FolderBrowser = New-Object System.Windows.Forms.FolderBrowserDialog  [void]$FolderBrowser.ShowDialog()  Return $FolderBrowser.SelectedPath}   Function Convert-UTF {  Param(    [String]$SourceFile  )  $Buffer = Get-Content $SourceFile -Encoding byte    $Encoding = [System.Text.Encoding]::GetEncoding("gb2312")  $String = $Encoding.GetString($Buffer)  Out-File -FilePath .\C2Htmp.txt -Encoding utf8 -InputObject $String} Function Write-Header {  Param(    [String]$OutFile,    [String]$Folder  )  '<!DOCTYPE NETSCAPE-Bookmark-file-1>' | Out-File -Encoding utf8 -FilePath $OutFile -NoClobber  '<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=UTF-8">' | Out-File -Encoding utf8 -FilePath $OutFile -Append  '<TITLE>Bookmarks</TITLE>' | Out-File -Encoding utf8 -FilePath $OutFile -Append  '<H1>Bookmarks</H1>' | Out-File -Encoding utf8 -FilePath $OutFile -Append  '<DL><P>' | Out-File -Encoding utf8 -FilePath $OutFile -Append  '<DT><H3>{0} --- {1}</H3>' -f $Folder, (Get-Date) | Out-File -Encoding utf8 -FilePath $OutFile -Append  '<DL><P>' | Out-File -Encoding utf8 -FilePath $OutFile -Append} Function Out-Bookmark {  Param(    [Object]$File,    [String]$Outfile  )  for($i=0; $i -lt $File.Length; $i++) {    $tmpFile = $File[$i] | % { $_.BaseName }    Write-Host "Converting: " $File[$i]    Convert-UTF $File[$i]    '<DT><H3>' + $tmpFile + '</H3></DT>' | Out-File -Encoding utf8 -FilePath $OutFile -Append    '<DL><P>' | Out-File -Encoding utf8 -FilePath $OutFile -Append    $Lines = (Get-Content ".\C2Htmp.txt")    for($j=2; $j -lt $Lines.Length; $j+=2) {      '<DT><A HREF="{0}">{1}</A>' -f $Lines[$j].Substring($Lines[$j].IndexOf("=") + 1), `                                     $Lines[$j - 1].Substring($Lines[$j - 1].IndexOf("=") + 1) `                                     | Out-File -Encoding utf8 -FilePath $OutFile -Append    }    '</DL><P>' | Out-File -Encoding utf8 -FilePath $OutFile -Append    Remove-Item '.\C2HTmp.txt'  }  '</DL><P>' | Out-File -Encoding utf8 -FilePath $OutFile -Append} If($PSVersionTable.PSVersion.Major -lt 4) {  Write-Host '** Script requires at least Powershell V4 **'} else {  $sFolder = (Get-Folder)  If($sFolder -eq '') {Exit}  Write-Host '-- Conversion started --'  $aFiles = (Get-ChildItem -Include *.cgp -Path ($sFolder + "\*"))  If(($sFolder.LastIndexOf('\') + 1) -eq $sFolder.Length) {  $sOutfile =  ($sFolder | % { $_.Substring(0, $_.LastIndexOf('\') + 1) }) `                + 'CGP2HTML-' + ("{0:yyyy}" -f (Get-Date)) + ("{0:MM}" -f (Get-Date)) `                + ("{0:dd}" -f (Get-Date)) + ('{0:hh}' -f (Get-Date)) `                + ('{0:mm}' -f (Get-Date)) + ('{0:ss}' -f (Get-Date)) + '.html'  } else {  $sOutfile =  $sFolder + '\' + 'CGP2HTML-' + ("{0:yyyy}" -f (Get-Date)) `                + ("{0:MM}" -f (Get-Date)) + ("{0:dd}" -f (Get-Date)) `                + ('{0:hh}' -f (Get-Date)) + ('{0:mm}' -f (Get-Date)) `                + ('{0:ss}' -f (Get-Date)) + '.html'  }  Write-Host '-- Conversion finished --'  Out-Bookmark $aFiles $sOutfile  Write-Header $sOutfile $sFolder}Write-Host ''Write-Host 'Output file: ' $sOutfile -foregroundcolor "blue" -backgroundcolor "yellow"Write-Host ''Write-Host 'Press a key to exit ...'cmd /c pause | out-null

Cocoa:
Hi 4wd,
I'm getting a window with errors when double-clicking the shortcut. It was gone too fast, but after several tries I managed to capture this scrnsht. After some research, it seems this is due to the fact the default security settings in Windows does not allow the execution of unsigned scripts. Is there a way you can sign it? Or do I need to permanently set the security level to "unsigned" in order to run the script? I hope there is a more secure workaround to avoid opening a permanent security risk for all unsigned scripts on my system.



I found this while searching for a solution. Perhaps you can make use of it, or help me understand how to use it?

On my machine that I use to dev scripts, I will use -unrestricted as above. When deploying my scripts however, to an end user machine, I will just call powershell with the -executionpolicy switch:
powershell.exe -noprofile -executionpolicy bypass -file .\script.ps1
--- End quote ---

4wd:
On my machine that I use to dev scripts, I will use -unrestricted as above. When deploying my scripts however, to an end user machine, I will just call powershell with the -executionpolicy switch:
powershell.exe -noprofile -executionpolicy bypass -file .\script.ps1
--- End quote ---
-Cocoa (June 27, 2015, 09:57 PM)
--- End quote ---

Try adding the -noprofile -executionpolicy bypass switches to the command line in the shortcut.

EDIT: This worked, it allowed the script to run after I changed my policy back to AllSigned, (mine's normally at RemoteSigned).



BTW, you did amend any path in the shortcut to point to wherever you've put the script, right?

Is there a way you can sign it?
--- End quote ---

Yes, but that means you'd need to import a certificate into your system that I create - bit much for one script.

Cocoa:
Try adding the -noprofile -executionpolicy bypass switches to the command line in the shortcut.
-4wd (June 27, 2015, 10:32 PM)
--- End quote ---
Tried it, but this time all it shows is a blinking white input cursor  :huh:


BTW, you did amend any path in the shortcut to point to wherever you've put the script, right?
--- End quote ---
Which path exactly do you mean? If you mean the "start in" box for the shortcut, I removed the old path. Based on previous experience with shortcuts in general, I didn't fill in any new ones because I didn't think it was necessary, but now I have updated it. As with the previous result, running the shortcut gets the same white blinking cursor and nothing else.

After further consideration, I've also tried replacing the -File with -"C:\Program Files (x86)\Green Browser\Groups", which is where the cgp files are stored, but this time I once again got a window with red error messages that disappeared too fast for me to read or screenshot. I tried running it repeatedly after that to capture a screenshot, but it seems all I'm getting now are blank windows that last less than a second, without the error messages anymore.

4wd:
-File with -"C:\Program Files (x86)\Green Browser\Groups", which is where the cgp files are stored, ...-Cocoa (June 29, 2015, 06:56 PM)
--- End quote ---

The -File argument points to where the script is which is why I said this:

BTW, you did amend any path in the shortcut to point to wherever you've put the script, right?-4wd (June 27, 2015, 10:32 PM)
--- End quote ---

So, if you extracted the script into the folder C:\Powershell Scripts and put the shortcut on your Desktop, then the shortcut needs to be edited to show:

%SystemRoot%\system32\WindowsPowerShell\v1.0\powershell.exe -noprofile -executionpolicy bypass -File "C:\Powershell Scripts\CGP2HTML.ps1"

I updated the shortcut in the archive with the necessary parameters.

You could also start a CLI, change to the folder where the script is, and type in the command:

powershell -noprofile -executionpolicy bypass -File "CGP2HTML.ps1"

REQ: Convert/Export Certain Browser's "Groups" as Chrome Bookmarks

FWIW, running via the shortcut works on all the machines I have access to here, when run from a flash drive.

Navigation

[0] Message Index

[#] Next page

[*] Previous page

Go to full version