grab text in emeditor from external windows potplayer application - emeditor

i can copy complete playlist along with path from the potplayer playlist using control+a followed by control+alt+c commands. potplayer is available at the following address
C:\Program Files (x86)\The Kmplayer\PotPlayerMini64.exe.
Is it possible to grab text from the above player from emeditor macro code? Is it possible to send messages to external windows and from there get the text copied to emeditor?

I am not sure about the potplayer you are using. However, If you know the window title or class name of the window where you want to send the Ctrl+A and Ctrl+Alt+C keys, you can write a similar code like this:
wnd = shell.FindWindow( "", "potplayer window title" );
wnd.SetForeground();
shell.SendKeys( "^a" );
Sleep( 100 );
shell.SendKeys( "^%c" );
If you don't know the window title or class name, but running the app path "C:\Program Files (x86)\The Kmplayer\PotPlayerMini64.exe" activates the window, you can run this:
WshShell = new ActiveXObject( "WScript.Shell" );
WshShell.Run( "C:\\Program Files (x86)\\The Kmplayer\\PotPlayerMini64.exe" );
Sleep( 1000 );
shell.SendKeys( "^a" );
Sleep( 100 );
shell.SendKeys( "^%c" );
References
FindWindow: http://www.emeditor.org/en/macro_shell_find_window.html
SendKeys: http://www.emeditor.org/en/macro_shell_send_keys.html

Related

how to auto select and copy filtered results in emeditor

presently em editor filter toolbar is having all options except option of auto selecting and copying filtered results to clipboard. manually i have to select and copy the filtered results.
i need help on two issues.
filter results to be automatically copied to clipboard. can you add option of auto select and copy filter results
?
the following code to be appeneded to the above macro code. editor.ExecuteCommandByID(4445); WshShell = new ActiveXObject( "WScript.Shell" );
WshShell.Run ( "PotPlayerMini64.exe /clipboard" );
please help me.
Here is a macro snippet to select all the text in the editor (after filtered), and copy the selection to the Clipboard, followed by your code. You will run this macro after you filter a document.
document.selection.SelectAll(); // Select All
document.selection.Copy(eeCopyUnicode); // Copy the selection to the Clipboard
WshShell = new ActiveXObject( "WScript.Shell" ); // your macro
WshShell.Run ( "PotPlayerMini64.exe /clipboard" );
If you want to include filter in your macro, you can use this:
strFilter = prompt( "Filter:", "" ); // Prompt for a string
document.Filter( strFilter, 0, 0 ); // Filter (case-insensitive)
document.selection.SelectAll(); // Select All
document.selection.Copy(eeCopyUnicode); // Copy the selection to the Clipboard
WshShell = new ActiveXObject( "WScript.Shell" ); // your macro
WshShell.Run ( "PotPlayerMini64.exe /clipboard" );

Window("hwnd:=" & handle).Restore is causing Object not visible error

I have an application that opens up some new tabs. I'm trying to cycle through these tabs, look at them, and then close them.
Dim tab_children, oDesc
Set oDesc = Description.Create
oDesc("micclass").value = "Browser"
Set tab_children = Desktop.ChildObjects(oDesc)
Dim title, handle, cTime
For i = 0 To tab_children.Count-1 Step 1
title = tab_children(i).GetROProperty("title")
handle = tab_children(i).GetROProperty("hwnd")
Window("hwnd:=" & handle).Restore
msgbox title & ": " & handle
Next
When we try to execute the .Restore, I receive an "object not visible" error. The tab that we're trying to restore is not the one that has focus, could that be the issue and if so how can we resolve it? I was under the impression that .Restore would bring that tab into focus based off of this thread, http://www.advancedqtp.com/old_forums/viewtopic.php?t=1970
The IDE I'm using is QTP, the Browser is IE.
A potential work around that I've been thinking about:
After the application opens up the new tabs, the last opened tab has focus. If we close that one, the 2nd to last has focus, all the way down to the original application's tab. Perhaps there's a way to utilize this information.
Restore has worked for me in the past, try using Activate-
Window("hwnd:=" & handle).Activate
Edited: Just tested the following and its working on my machine-
'Create Browser Descriptor
Set oBrowser=Description.Create
oBrowser("micclass").Value="Browser"
'Get the child objects
Set oBrowser=Desktop.ChildObjects(oBrowser)
totalcount = oBrowser.Count-1
For i=0 to totalcount
If Browser("micclass:=Browser", "index:="&i).Exist(0) Then
'get the hwnd everytime there's an iteration
ohwnd= Browser("micclass:=Browser", "index:=" & i).GetROProperty("hwnd")
'For debugging purposes
name = Browser("hwnd:="&ohwnd).GetROProperty("title")
msgbox name
Set oBrowser=Browser("hwnd:="&ohwnd)
'Page descriptor
Set oPage=Description.Create
oPage("micclass").Value="Page"
Set oPage=Browser("hwnd:="&ohwnd).ChildObjects(oPage)
For n=0 to oPage.Count-1
If oPage(n).Exist(0) Then
oBrowser.Close
Exit For
End If
Next
End If
Next
If you want to close only a particular page you can use the GETROPREPERTY("Title") in the If loop - If oPage(n).Exist(0)

Photoshop javascript save error 8800

In my javascript, in Windows 7, Photoshop CS2 & Photoshop CS5, it throws an error:
Error 8800: General Photoshop error occurred. This functionality may not be available in this version of Photoshop.
- Could not save a copy as "C:...\wcb-010B-11Y.jpg" because the file could not be found.
Line: 458
-> docRef.saveAs( saveFile, jpgSaveOptions, true, Extension.LOWERCASE );
here is a summary of the code to save the image:
var selectedSaveDir = "~/Desktop/";
var sFileNamePreFix = "wcb-";
var docRef = app.activeDocument;
var docName = app.activeDocument.name;
var docNewName = docName.substr( 0, docName.length - 4 ); // strip file extension
var sNewDocName = sFileNamePreFix + docNewName + ".jpg"
var sNewFileName = selectedSaveDir + sNewDocName;
//alert( "sNewFileName = " + sNewFileName ); // test to verify correct location
var saveFile = new File(sNewFileName);
jpgSaveOptions = new JPEGSaveOptions();
jpgSaveOptions.quality = 12;
docRef.saveAs(saveFile, jpgSaveOptions, true, Extension.LOWERCASE);
In Windows XP, this script works very well in CS2 with no problems.... just in Windows 7 is where this issue occurs using CS2 or CS5.
The problem seems to be similar to : Photoshop Javascript scripting saving and closing document
But I don't know his OS.
I've added the "alert(" and confirmed the save folder & name is correct and can be saved to, but same issue.
Could it be a UAC issue in Windows 7 ? and how do you Fix it ? I've turned off all UAC settings (I think I did it correctly), but it still occurs.
Any Help ?
You missed out " var docRef = app.activeDocument;" (which i've added); but apart from that, in CS2 the script saves out a jpeg to the desktop (wcb-text test.jpg). It's obvious, but have you made sure the image is flattened or doesn't contain any information that cannot be stored in a jpeg - like paths for example.
Try forcing a flatten before saving
//flatten the image
docRef.flatten();
Another thing to try is to save out the file to another directory. I know that long file names (especially with spaces in) can cause problems - I think there's a limit to 300 characters in the file path.
I just found that, in new versions of PS this particular path variable gives the error 8800:
var selectedSaveDir = "~/Desktop/";
Use full path instead and use apostrophes instead of quotes:
var selectedSaveDir = 'C:/Users/yourname/Desktop/';

How do I write to the output window in Visual Studio 2010 AddIn?

I'm writing a simple Visual Studio 2010 Add-In to do a common copying job here at work (getting dlls from libs sln).
I want the progress of the copying to be written to the output window.
I tried Trace.WriteLine(...) expecting that to make it, but it doesn't when I run the add-in in the debugger. I have not tried it any other way yet.
I found some examples of doing that in Visual Studio 2008, but the required libs are not available to reference.
Can anyone point me to how to write to the output window? My googling skills have failed me.
I've done this for a macro I wrote:
Window window = dte.Windows.Item(EnvDTE.Constants.vsWindowKindOutput);
OutputWindow outputWindow = (OutputWindow) window.Object;
outputWindow.ActivePane.Activate();
outputWindow.ActivePane.OutputString(message);
Here is a link for the DTE Interface:
http://msdn.microsoft.com/en-us/library/envdte.dte(v=VS.100).aspx
As Robert pointed out, John's code will throw an exception when there is no ActivePane. If there is an active pane, it will use whichever pane is active.
One issue I have with Robert's example is depending on where you create the pane, which in my case is the Exec method, it will create multiple panes with the same name each time it is run.
Including my example as to how I got around that issue. Pretty simple, just check for the existence of the window first...
Window window = _applicationObject.Windows.Item( EnvDTE.Constants.vsWindowKindOutput );
OutputWindow outputWindow = ( OutputWindow )window.Object;
OutputWindowPane outputWindowPane = null;
for ( uint i = 1; i <= outputWindow.OutputWindowPanes.Count; i++ )
{
if ( outputWindow.OutputWindowPanes.Item( i ).Name.Equals( OUTPUT_WINDOW_NAME , StringComparison.CurrentCultureIgnoreCase ) )
{
outputWindowPane = outputWindow.OutputWindowPanes.Item( i );
break;
}
}
if ( outputWindowPane == null )
outputWindowPane = outputWindow.OutputWindowPanes.Add( OUTPUT_WINDOW_NAME );
outputWindowPane.OutputString( "Message" );
I am writing a Visual studio add-in and had the same problem, however when trying the above answer I found that the line:
outputWindow.ActivePane.Activate();
gave an error.
NullReferenceException -- Object reference not set to an instance of an object.
However I have now found a slightly different way to solve the problem:
Window window = applicationObject.Windows.Item(Constants.vsWindowKindOutput);
OutputWindow outputWindow = (OutputWindow)window.Object;
OutputWindowPane owp;
owp = outputWindow.OutputWindowPanes.Add("new pane");
owp.OutputString("hello");

How do I determine the image dimensions of a tiff file?

I have a vbscript script and I need to chew through a directory of .tif files. For each file, I need to determine if the file is proportioned as a landscape or a portrait. Basically, I need to be able to get the image dimensions for each file. So for, I have seen some examples of people reading the file file headers to extract this sort of information from jpg or bmp files. Has anyone done the same thing to extract the dimensions for a tiff file?
In VBScript, you can determine the image dimensions in two ways:
Using the WIA Automation Library (download link, MSDN documentation, an excellent Hey, Scripitng Guy! article on the subject). Once you have the wiaaut.dll library registered, you can use the following simple code:
Set oImage = CreateObject("WIA.ImageFile")
oImage.LoadFile "C:\Images\MyImage.tif"
WScript.Echo "Width: " & oImage.Width & vbNewLine & _
"Height: " & oImage.Height
Using the GetDetailsOf method to read the corresponding extended file properties. This is a native Windows scripting method, so no external libraries are required; but the code is longer:
Const DIMENSIONS = 31
CONST WIDTH = 162
CONST HEIGTH = 164
Set oShell = CreateObject ("Shell.Application")
Set oFolder = oShell.Namespace ("C:\Images")
Set oFile = oFolder.ParseName("MyImage.tif")
strDimensions = oFolder.GetDetailsOf(oFile, DIMENSIONS)
strWidth = oFolder.GetDetailsOf(oFile, WIDTH)
strHeigth = oFolder.GetDetailsOf(oFile, HEIGTH)
WScript.Echo "Dimensions: " & strDimensions & vbNewLine & _
"Width: " & strWidth & vbNewLine & _
"Height: " & strHeigth
This script outputs something like:
Dimensions: 2464 x 3248
Width: 2464 pixels
Height: 3248 pixels
so if you need plain numbers, you'll have to extract them from the returned strings.
There's also another problem with this method - the property indexes (those constants in the beginning on the script) are different in different Windows versions, as I explained in this answer. The above script is for Windows 7, but if you use another Windows versions or if you want the script to work on different Windows versions, you'll need to use version-specific indexes. The most complete list of available property indexes is here.
I would recommend using Atalasoft's DotImage Photo Its powerful & it's free! But, it's a .NET package, so you'll have do some Regasm Magic to make it work. Go check out Use vb.net in VBScript before you get started.
Here is the code you'll need to get the dimensions.
Public Function GetHeight(path As String) As Integer
Using stm As New FileStream(path, FileMode.Open, FileAccess.Read, FileShare.Read)
Dim decoder As New TiffDecoder()
If Not decoder.IsValidFormat(stm) Then
Throw New Exception("not a TIFF")
End If
Dim image As AtalaImage = decoder.Read(stm, Nothing)
Return image.Height
' Return image.Width --- To return the Width.
End Using
End Function

Resources