Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate
Photo

Change File Association/File Extension or Open with..


  • Please log in to reply
18 replies to this topic
Esther 21
  • Members
  • 30 posts
  • Last active: Oct 15 2010 10:04 AM
  • Joined: 20 Mar 2010
Hi,

I would like to change my file association/ file extension or to open my file with other applications.

Example
When I click on .txt or .doc or .docx files it opens my openoffice software instead.

Hmm..any ideas?

Thank you all.


[/u]

None
  • Members
  • 3199 posts
  • Last active: Nov 05 2015 09:55 PM
  • Joined: 28 Nov 2009
On XP
Tools :arrow: Folder Options
Select file types tab
Find the extension and select it
Click Change button and select your new program

codybear
  • Members
  • 600 posts
  • Last active: Feb 09 2015 12:41 PM
  • Joined: 15 Sep 2009
also look into the following command prompt commands:
ftype
assoc

You can use that, and can write a script with autohotkey to reassociate your programs if you like. I have a script that does so for my portable programs on my flash drive for when I go to school. (they have a program that changes all settings back to how they have it setup, so my changes don't stay around like they would normally).

<!-- m -->http://ss64.com/nt/<!-- m -->

Esther 21
  • Members
  • 30 posts
  • Last active: Oct 15 2010 10:04 AM
  • Joined: 20 Mar 2010
Hi
Thanks for you all for you reply, but if is possible if i write them into a AutoHotKey script? So there when ever i just click on the file (txt or doc or docx) i am able to open with open office?

Leef_me
  • Moderators
  • 8510 posts
  • Last active: Sep 10 2015 05:50 AM
  • Joined: 08 Apr 2009
>>Thanks for you all for you reply, but if is possible if i write them into a AutoHotKey script?

It seems like you did not understand. You got 2 different answers but you did not pick the one you want. You just stated that you wanted a script.

Which do you want? :roll:

Esther 21
  • Members
  • 30 posts
  • Last active: Oct 15 2010 10:04 AM
  • Joined: 20 Mar 2010
Hi Leef_me,

Its you, Thanks for replying.. hehe. I understand what "None" is saying but i wish to do the same steps using AutoHotkey not doing it manually .

And for CodyBear, i am not really good in cmd but i did read the website CodyBear stated however wasn't too clear about it.

Below is the code i written, i am still missing out the "open with" command.

Mbutton::
Send ^c
fn=%clipboard%
Ext:=Substr(fn,-3) ; detect the extension
myNotepad =.txt
If Ext =%myNotepad%
{...Read from INI File...notepad = .doc }

Splitpath, fn,,dir,,name_no_ext
new = %dir%\%name_no_ext%%notepad%
run new ;
-> but missing out "open with" command...

Leef_me
  • Moderators
  • 8510 posts
  • Last active: Sep 10 2015 05:50 AM
  • Joined: 08 Apr 2009
Would you please edit your post and put your script contents within [code][/code] tags

The way you have written your script suggests to me that the subject title you chose was very poor.
It seems like you just want to open a file with whatever program you write into the script.

Btw, you comments {...} and " -> " are terrible to try to understand.

Esther 21
  • Members
  • 30 posts
  • Last active: Oct 15 2010 10:04 AM
  • Joined: 20 Mar 2010
Hi Leef_me,

I chosen this title as this was what I am trying to do, so i thought to be concise. Anyway i have make changes to the post hope this helps.

Leef_me, I am trying to have something similar to Windows "open with" command but using AutoHotkey insted. Hmm..

Mbutton::
Send ^c
fn=%clipboard%
Ext:=Substr(fn,-3) ; detect the extension
myNotepad =.txt
If Ext =%myNotepad%
{
IniRead, Notepad, C:\Documents and Settings\Desktop\config.ini, General, Notepad
}
Splitpath, fn,,dir,,name_no_ext
new = %dir%\%name_no_ext%%notepad%
run new ;
;;Missing out "open with" command.

Thank You all for your replies. I am open to suggestion :)

emmanuel d
  • Members
  • 519 posts
  • Last active: Jul 15 2017 12:04 PM
  • Joined: 29 Jan 2009
something like this?
GroupAdd, Explore, ahk_class CabinetWClass			; Add a class to the group

GroupAdd, Explore, ahk_class ExploreWClass			; Add a other class to the group

#ifWinActive,ahk_group Explore  				; Set hotkeys to work in explorer only

Mbutton::

	SelectedFile:=ExplorerGetCurentFolder() "\" ExplorerGetFileName()

	SplitPath, SelectedFile, OutFileExt, OutDir, OutExt, OutFile, OutDrive

	menu,OpenWith,Add					; add nothing to prevent error when deleting

	menu,OpenWith,delete				; delete the menu incase you want diferent items for different filetypes

	menu,OpenWith,Add,Notepad,Openwith	; create the menuitems

	menu,OpenWith,Add,Notepadpp,Openwith

	menu,OpenWith,Add,Regedit,Openwith

	menu,OpenWith,Add,Commandline,Openwith

	menu,OpenWith,Show					; show the menu

	return

Openwith:

	Notepad=Notepad.exe					; assign the exe to the menuitem 

	Notepadpp=Notepad++.exe			; this meens that if % A_ThisMenuItem = Notepadpp then % %A_ThisMenuItem% = Notepad++.exe

	Regedit=Regedit.exe

	Commandline=cmd.exe

	run % %A_ThisMenuItem% " " SelectedFile ; run the app associated with the menuitem

	return

ExplorerGetCurentFolder() {

	if (A_OSVersion="WIN_XP")					; If we have XP

		ControlGetText Pad, Edit1, A			; Get the Folder we are in

	else if (A_OSVersion="WIN_VISTA") {		; If we have vista

		ControlGetText, Pad, toolbarwindow322, ahk_class CabinetWClass	; Get the folder from the adressbar

		stringreplace, Pad, Pad,% "Address: ",% ""	; Strip the word Adress: from it

		}

	if (SubStr(Pad, 0, 1)="\")				; If last Char is a \

		StringTrimRight, Pad, Pad,1			; Remove it

	Return,%Pad%								; Return the Currrent folder

	}

ExplorerGetFileName() {

	if (A_OSVersion="WIN_XP")					; If we have XP

		ControlGet, Selected, List, Selected Col1, SysListView321, A	; Get the file, Foldername

	else if (A_OSVersion="WIN_VISTA") {		; If it's Vista

		BlockInput, Mousemove 					; Block mouse movement

		oldclip := ClipboardAll					; Backup the ClipBoard

		clipboard=								; Reset the ClipBoard

		send, ^c								; Send the copy command, Ctrl+C

		ClipWait, 0.5							; Wait until the ClipBoard contains data

		Selected=%clipboard%					; Get the data from the ClipBoard

		clipboard := oldclip					; Restorte the old ClipBoard data

		BlockInput, MousemoveOff				; Enable mouse movement

		}

	Return,%Selected%							; Return the name of the selected item

	}

IsFolder(FileOrFolder) {

	if InStr(FileExist(FileOrFolder), "D")

		return,%true%

	else return,%false%

	}

or is it more something like this you want:
GroupAdd, Explore, ahk_class CabinetWClass			; Add a class to the group

GroupAdd, Explore, ahk_class ExploreWClass			; Add a other class to the group

#ifWinActive,ahk_group Explore  				; Set hotkeys to work in explorer only

Mbutton::

	SelectedFile:=ExplorerGetCurentFolder() "\" ExplorerGetFileName()

	SplitPath, SelectedFile, OutFileExt, OutDir, OutExt, OutFile, OutDrive

	TxtOpen=Notepad.exe		; this you can all read from ini if you want

	IniOpen=Notepad.exe

	logOpen=Notepad.exe

	RegOpen=Notepad.exe

	CsvOpen=Notepad.exe

	AhkOpen=Notepad.exe

	if %OutExt%Open

		run % %OutExt%Open " " SelectedFile ;

	return

ExplorerGetCurentFolder() {

	if (A_OSVersion="WIN_XP")					; If we have XP

		ControlGetText Pad, Edit1, A			; Get the Folder we are in

	else if (A_OSVersion="WIN_VISTA") {		; If we have vista

		ControlGetText, Pad, toolbarwindow322, ahk_class CabinetWClass	; Get the folder from the adressbar

		stringreplace, Pad, Pad,% "Address: ",% ""	; Strip the word Adress: from it

		}

	if (SubStr(Pad, 0, 1)="\")				; If last Char is a \

		StringTrimRight, Pad, Pad,1			; Remove it

	Return,%Pad%								; Return the Currrent folder

	}

ExplorerGetFileName() {

	if (A_OSVersion="WIN_XP")					; If we have XP

		ControlGet, Selected, List, Selected Col1, SysListView321, A	; Get the file, Foldername

	else if (A_OSVersion="WIN_VISTA") {		; If it's Vista

		BlockInput, Mousemove 					; Block mouse movement

		oldclip := ClipboardAll					; Backup the ClipBoard

		clipboard=								; Reset the ClipBoard

		send, ^c								; Send the copy command, Ctrl+C

		ClipWait, 0.5							; Wait until the ClipBoard contains data

		Selected=%clipboard%					; Get the data from the ClipBoard

		clipboard := oldclip					; Restorte the old ClipBoard data

		BlockInput, MousemoveOff				; Enable mouse movement

		}

	Return,%Selected%							; Return the name of the selected item

	}

IsFolder(FileOrFolder) {

	if InStr(FileExist(FileOrFolder), "D")

		return,%true%

	else return,%false%

	}


Stopwatch emdkplayer
the code i post falls under the: WTFYW-WTFPL license

http://www.ahkscript.org/ the new forum


n-l-i-d
  • Guests
  • Last active:
  • Joined: --
Normally, you'd need to edit the registry to make the system open files in a specific program. One can do this with AutoHotkey.

However: to be able to make the system open files in a specific program without editing the registry (if you are not a Super User/Administrator or have to/want to run portable) takes a bit more.

Fortunately, this has already been done (in AHK!), and its name is eXpresso

HTH

emmanuel d
  • Members
  • 519 posts
  • Last active: Jul 15 2017 12:04 PM
  • Joined: 29 Jan 2009
true, eXpresso (alias Coffee) does it, but like for me i want to do it myself.
lots of things i dont like in expresso so i made my own.

but it is not clear what she wants realy.
does she has apps on d: and want to register the fileextentions everytime she reinstalls the os.
or does she want to catch filextentions in explorer for use on a usbstick(portable)?

on my pc all apps are porteble and on d:
so i am doing filextentions to reg
now i am working on caching fileextentions in explorer, like expresso but more advanced.
for the moment i am using both until the reg one becomes obsolete.

like she does it with middle button it looks like she wants to keep the original associations, and add custom items

she needs to be spicific in these matters, becouse if she wants left double click, thats no problem

Stopwatch emdkplayer
the code i post falls under the: WTFYW-WTFPL license

http://www.ahkscript.org/ the new forum


codybear
  • Members
  • 600 posts
  • Last active: Feb 09 2015 12:41 PM
  • Joined: 15 Sep 2009
Emmanuel, I can't wait to see your finished product...hopefully you'll release it. Sounds really promising.

Sorry to OP for offtopic posting.

Esther 21
  • Members
  • 30 posts
  • Last active: Oct 15 2010 10:04 AM
  • Joined: 20 Mar 2010
Hi guys and emmanuel d,

emmanuel d thank you so much your effort. I am currently testing the code you posted. Sorry i haven make myself clear of what i am trying to do here.

The story is, i would like to open a file with another application. I know there is such function on windows already. But I would like to use it using AutoHotKeys.

I am trying the codes now, will update you guys shortly.

Really, thank you for the effort!!! :D

None
  • Members
  • 3199 posts
  • Last active: Nov 05 2015 09:55 PM
  • Joined: 28 Nov 2009
How complicated do you want to get?
Select a File then Hold Control and press RButton
^RButton::
Path:=GetFile()
Gui, Add, Text,, %Path%`nOpen With
Gui, Add, Button,,Notepad
Gui, Add, Button,,Word
Gui, Show,,OpenWith
Return

ButtonNotepad:
Gui, Cancel
Run Notepad.exe "%Path%"
Return

ButtonWord:
Gui, Cancel
Run C:\Program Files\Microsoft Office\OFFICE11\WINWORD.EXE "%Path%"
Return

GetFile() {
ClipSave:=ClipboardAll
Clipboard:=""
Loop
{
Send ^c
ClipWait, .2
If !ErrorLevel
 Break
}
Path=%clipboard%
Clipboard:=ClipSave
Return Path
}


emmanuel d
  • Members
  • 519 posts
  • Last active: Jul 15 2017 12:04 PM
  • Joined: 29 Jan 2009
well, more complicated then your code, we want for instance that it only works in explorer, and not in other apps so #ifwinactive is needded.
then i dont think we want a gui, or only one fore settings.
and i use doubleclick like normal and rbutton for a menu. so it is like normal explorer but wit my fileassociations, and that is complicated.

Stopwatch emdkplayer
the code i post falls under the: WTFYW-WTFPL license

http://www.ahkscript.org/ the new forum