Jump to content

How do I detect HIGHLIGHTED items?


Recommended Posts

I am automating a part of this sequence where you go to explorer >> tools >> folder options >> file types

then i want to scroll down to the 'T' section and change TIF and TIFF to "Imaging"

i posted this earlier about 1-2 weeks back and people suggested changing the registry. i have failed to do so. i figure i can just check every file type that starts with T and see if it is TIF or TIFF.

Run("explorer")
WinWaitActive("My Documents")
Send("!t");alt+t
Send("o")
WinWaitActive("Folder Options")
$foptionsPos = WinGetPos("Folder Options")
MouseClick("left", $foptionsPos[0]+130, $foptionsPos[1]+40)
Sleep(6000)
MouseClick("left", $foptionsPos[0]+100, $foptionsPos[1]+130)
Send("t")

can anyone help with what i have so far? i know there are better ways to do what i just coded... but i'd like to just get this over with.

thanks!

------------------------------------------------------------------If it were up to me, all computer stuff would work

Link to comment
Share on other sites

In AutoIt Spy i get this as part of it

-------------------------------------------------------

>>>>>>>>>>>( Visible Window Text )<<<<<<<<<

File Types

Registered file &types:

&New

&Delete

Opens with:

Imaging

&Change...

You have customized files with extension 'TIF'. To restore these files to their default type (FT000002), click Restore.

&Restore

Details for 'TIF' extension

OK

Cancel

&Apply

-------------------------------------------------------

I want to detect "Details for 'TIF' extension" and "Details for 'TIFF' extension"... how do i do this? which variable do i pass?

------------------------------------------------------------------If it were up to me, all computer stuff would work

Link to comment
Share on other sites

WinWaitActive("Folder Options")
$text = WinGetText("Folder Options", "")
MsgBox(0, "Text read was:", $text)
$result = StringInStr($text, "File Types")
if $result <> 0 Then
MsgBox(0, "got", "the right tab")
EndIf
$result = StringInStr($text, "TIF")
if $result <> 0 Then
MsgBox(0, "got", "the right selection")
EndIf

Will msgbox you "got, the right tab" if your on the "File types" tab, and then "got, the right selection" if you've selected one of the "TIF Image Document" entries.

Hope thats what you want.

Sitting comfortably behind the code.

Link to comment
Share on other sites

Now i tried :ph34r:

It works, by changing that key, you change what software to use when open TIF.

Try this:

$var = RegRead("HKEY_CLASSES_ROOT\TIFImage.Document\shell\open\command", "")
MsgBox(4096, "Program used for TIF:", $var)
Edited by Doxie

Were ever i lay my script is my home...

Link to comment
Share on other sites

That key needs to be read at run-time, however, by reading the default entry for HKEY_CLASSES\ROOT\.tif and then opening whatever key it says. For example, on Doxie's computer, the default is apparently "TIFImage.Document" so you can find the shell handlers and other related stuff at "HKEY_CLASSES_ROOT\TIFImage.Document". The same method can be used for any file extension. You can not safely assume all PC's will point to "TIFImage.Document" because some applications may copy that and add their own stuff to the copy, then redirect to the copy.

Link to comment
Share on other sites

True Valik,

A simple way to find out is:

Open Folder options / File Types

Scroll down to TIF

Press Advanced

Press EDIT "Open"

Copy "Application used to perform action"

Open Regedit

Press F3

Paste

Ok

Keep pressing F3 until you see you are on the right regkey.

That´s what i did.

Were ever i lay my script is my home...

Link to comment
Share on other sites

Sorry to bring this back up... I've been away and i still haent solved this problem.

I tried all of your solutions. Turns out i can use TIFImage.Document as my reference point.

However,

my registry already reads the correct value for HKEY_CLASSES_ROOT/TIFImage.Document/shell/open/command

Also, i have tried changing various values in HKEY_CLASSES_ROOT/.tif and HKEY_CLASSES_ROOT/.tiff with no success

------------------------------------------------------------------If it were up to me, all computer stuff would work

Link to comment
Share on other sites

Here's a short tutorial on file extensions and how they are stored in the registry:

Any extension that is registered on a system can be found at HKEY_CLASSES_ROOT\.extension.

In your case, HKEY_CLASSES_ROOT\.tif (And .tiff).

The default value you would get when doing something like RegRead() on that key is a ProgID for the extension. The ProgID will contain sub-keys which define the icon, shell commands (open, edit, run, et cetera) among other things.

All the shell commands are defined in a subkey which is HKEY_CLASSES_ROOT\{ProgID}\shell\{CommandName}

The default value of the CommandName will specify the name of the command which will appear in the context menu. Below this key is a sub-key called "command". This key points to the application which is used to launch the extension.

You can not just assume TIFImage.Document will be correct on any PC. You must retrieve that proper ProgID at run time from the registry. There could be an application installed which has created a new ProgID for the file extension, so your changes will not affect anything.

Edit: Fixed typo.

Edited by Valik
Link to comment
Share on other sites

I created this function some time ago and it looks like what you need.

Can you try my function and tell us if it solves your problem?

Reminds me, I know what your problem is!

To be able to solve this issue, you have to read the default value of the key.

And currently you can only do that with v3.0.102.

Workaround:

Export the key using "REGEDIT /A filename key".

Here's a modified version of my original UDF (with example) which can solve your problem and works on the current version of AutoIt.

MsgBox(0, "", "Program: " & Assoc(".TIF"))
Exit

;===============================================================================
;
; Description:      Returns the associated application by specifying an extension or a filename. (Modified version)
; Syntax:           Assoc($Filename)
; Parameter(s):  $Filename   - Filename or the 3 characters of the extension
;
; Requirement(s):   none
; Return Value(s):  On succes  - Returns the full path to associated application
;                   On failure  - Returns -1
;
; Author(s):        "SlimShady"
; Note(s):          none
;
;===============================================================================
Func Assoc($Filename)
   If StringRight($Filename, 3) = "exe" OR StringInStr($Filename, ".") = 0 Then Return -1
   $Ext = StringRight($Filename, 3)
   
   $Descr = ReadDefaultValue("HKEY_CLASSES_ROOT\." & $Ext)
   $Program = ReadDefaultValue("HKEY_CLASSES_ROOT\" & $Descr & "\Shell\Open\Command")
   
   $Match = StringInStr($Program, ".exe")
   If $Match = 0 Then
       Return -1
   EndIf

   $Program = StringLeft($Program, $Match + 3)
   Return $Program
EndFunc

Func ReadDefaultValue($Key)
   $Key = '"' & $Key & '"'
   $RegFile = @TempDir & '\TempregFile.reg'
   FileDelete($RegFile)
   RunWait(@ComSpec & ' /c REGEDIT /A ' & $RegFile & ' ' & $Key, "", @SW_HIDE)

   $OpenRegFile = FileOpen($RegFile, 0)
   While 1
       $Line = FileReadLine($OpenRegFile)
       If StringLeft($Line, 1) = "@" Then
           FileClose($OpenRegFile)
           $value = StringTrimLeft($Line, 2)
           $value = StringReplace($value, '"', '')
           If StringLeft($value, 1) = "\" Then $value = StringTrimLeft($value, 1)
           $value = StringReplace($value, "\\", "\")
           Return $value
       EndIf
       Sleep(100)
   WEnd
EndFunc
Edited by SlimShady
Link to comment
Share on other sites

hmmm i am not sure how ReadDefaultValue works.. do you think you could debug this? I am getting an error on line 43.

Also, on line 23 and 24... you have a difference in the input values.... you have the following:

HKEY_CLASSES_ROOT\.

HKEY_CLASSES_ROOT\

hmmm... here's something though

when i change these values to what i want them to be for .tif, .tiff, and even TIFImage.Document and then i go to Explorer>>Tools>>File Options>>File Types.. nothing in that area changes when it concerns the actual file associations. I think there may other htings i am missing =(

------------------------------------------------------------------If it were up to me, all computer stuff would work

Link to comment
Share on other sites

Reminds me, I know what your problem is!

To be able to solve this issue, you have to read the default value of the key.

And currently you can only do that with v3.0.102.

Sorry... but no. Being able to read the default value by passing "" as the value parameter has been in AutoIt since the beginning.

$res = RegRead("HKEY_CLASSES_ROOT\.txt", "")
MsgBox(4096, "", $res)
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...