Jump to content

Changing this shortcut maker to add path as prompted?


Recommended Posts

Begging the indulgence of the group. I got the wonderful script below some time back from this forum. I'm finding that it's actually quite time-consuming as I must minimize everything, go to the desktop, open up the shortcut properties, add the path, close, then rename shortcut.

Is there any way to prompt the user for the URL and a name for the shortcut? I'm so useless with complicated things like this <sigh>.

;
; AutoIt v3.0
;




;FileCreateShortcut ( "file", "lnk" [, "workdir" [, "args" [, "desc" [, "icon" [, "hotkey" [, icon number [, state]]]]]]] )
FileCreateShortcut(@UserProfileDir & "\Application Data\Microsoft\Internet Explorer\Quick Launch\WXP\APP- Firefox Portable v2.0.0.3\FirefoxPortable.exe", @DesktopDir & '\FF shortcut.lnk','','""')



Sleep(500)
SoundPlay(@ScriptDir & "\WAVs\Beep 01.wav")
; message box saying "done"
MsgBox(64, 'Shortcut status ...', "Shortcut has been created on the desktop.", 2)




Exit
; finished

Thank you! :)

Link to comment
Share on other sites

I don't understand? Prompt user for the URL to what? Why does the shortcut name need to change?

Ah, good question. Sorry, one is involved in the problem and something so obvious wouldn't be known to anyone else. Sheesh, wasn't thinking on that one.

See, the script puts a shortcut to Firefox, in this case, on the desktop since the default is actually Internet Explorer. So in the end I have a shortcut to Firefox with the path like this:

"C:\Documents and Settings\gordind.TC\Application Data\Microsoft\Internet Explorer\Quick Launch\WXP\APP- Firefox Portable v2.0.0.3\FirefoxPortable.exe" ""

The shortcut comes out labelled "FF shortcut".

So after running this script, I'll copy the target URL, open the properties of this newly created shortcut and will add it in between the quotes after the path to the EXE.

Then I'll close the box, go back to the shortcut and rename it. I then dump it into an Outlook reminder, etc., etc., so that when I click on it, I'm taken to the needed URL with my browser of choice. Office stuff ... though I'm using Firefox portable, we run so much office stuff off the intranet which requires Internet Explorer so I never change my default browser to my portable Firefox. But then that makes life interesting. This script has made life much easier, but it would be a breeze if the script would prompt me for the target URL _and_ for the shortcut name so that the shortcut is easily made. Then just a question of dragging it to where I need it. The shortcut is ready to go after running the script.

Thanks. :)

Edited by Diana (Cda)
Link to comment
Share on other sites

If I read your posts correctly, this should be what you are looking for:

#include <GUIConstants.au3>
Dim $s_lnkPath
Dim $s_lnkURL

$s_lnkPath = FileSaveDialog("Select Shortcut Location",@DesktopDir,"Shortcuts (*.lnk)",16,"FF shortcut.lnk")
If @error Then Exit

;~ Started to do a simple inputbox, but then remembered that input boxes have a character limit of 254 characters.  Many urls can easily exceed 256 characters.
;~ $s_lnkURL = Inputbox("URL Input","Please input the URL that you would wish to have firefox open when the shortcut is double clicked:")

;Create GUI:
Dim $h_GUI, $h_Input, $h_OKBtn, $h_CpyFrmClipBtn, $msg
Dim $i_GUIWidth = 300
Dim $i_GUIHeight = 75
$h_GUI = GUICreate("Input",$i_GUIWidth,$i_GUIHeight,(@DesktopWidth - $i_GUIWidth)/2,(@DesktopHeight -$i_GUIHeight)/2,$WS_CAPTION + $WS_SYSMENU)

;Create Input Control:
Dim $i_InputLeft = 10
Dim $i_InputTop = 10
$h_Input = GUICtrlCreateInput("",$i_InputLeft ,$i_InputTop , $i_GUIWidth - (2*$i_InputLeft),25)

;Create OK Button:
Dim $i_OKWidth = 50
Dim $i_OKLeft = $i_GUIWidth - ($i_OKWidth + 10)
Dim $i_OKHeight = 23
Dim $i_OKTop = $i_GUIHeight - ($i_OKHeight + 10)
$h_OKBtn = GUICtrlCreateButton("&OK",$i_OKLeft,$i_OKTop,$i_OKWidth,$i_OKHeight)

;Create Copy URL From Clipboard Button:
Dim $i_CpyFrmClpWidth = 135
Dim $i_CpyFrmClpLeft = 10
Dim $i_CpyFrmClpHeight = 23
Dim $i_CpyFrmClpTop = $i_GUIHeight - ($i_CpyFrmClpHeight + 10)
$h_CpyFrmClipBtn = GUICtrlCreateButton("&Copy URL From Clipboard",$i_CpyFrmClpLeft,$i_CpyFrmClpTop,$i_CpyFrmClpWidth,$i_CpyFrmClpHeight)

;Set the OK Button as the Default Button:
GUICtrlSetState($h_OKBtn,$GUI_DEFBUTTON)

;Now that the GUI is complete, show the GUI to the user:
GUISetState()

While 1
    $msg = GUIGetMsg()
    Switch $msg
        Case $GUI_EVENT_CLOSE
            ;The user requested the program close and the script will now exit
            Exit
        Case $h_OKBtn
            If GUICTrlRead($h_Input) <> "" Then
                $s_lnkURL = GUICtrlRead($h_Input)
                Exitloop
            Else
                Msgbox(48,"Error","You didn't input any text.")
            EndIf
        Case $h_CpyFrmClipBtn
            GUICtrlSetData($h_Input,ClipGet())
    EndSwitch
WEnd

GUIDelete($h_GUI)

;FileCreateShortcut ( "file", "lnk" [, "workdir" [, "args" [, "desc" [, "icon" [, "hotkey" [, icon number [, state]]]]]]] )
If FileCreateShortcut(@UserProfileDir & "\Application Data\Microsoft\Internet Explorer\Quick Launch\WXP\APP- Firefox Portable v2.0.0.3\FirefoxPortable.exe",$s_lnkPath,'','"'&$s_lnkURL&'"') Then
    MsgBox(64, 'Done!', "Shortcut was successfully created.")
Else
    MsgBox(16, 'Error!', "Shortcut was not created.")
EndIf

Exit

I am pretty sure this is what you meant when you requested that the user be able to select the shortcut's location as well as the shortcut's name.

- The Kandie Man ;-)

"So man has sown the wind and reaped the world. Perhaps in the next few hours there will no remembrance of the past and no hope for the future that might have been." & _"All the works of man will be consumed in the great fire after which he was created." & _"And if there is a future for man, insensitive as he is, proud and defiant in his pursuit of power, let him resolve to live it lovingly, for he knows well how to do so." & _"Then he may say once more, 'Truly the light is sweet, and what a pleasant thing it is for the eyes to see the sun.'" - The Day the Earth Caught Fire

Link to comment
Share on other sites

If I read your posts correctly, this should be what you are looking for:

...

I am pretty sure this is what you meant when you requested that the user be able to select the shortcut's location as well as the shortcut's name.

- The Kandie Man ;-)

OMG, this is amazing! Yes, that is exactly what I needed and it's just way too kewl! I'm always in awe of what you guys can do. This just made running Firefox portable that much easier and efficient! Thank you! :)
Link to comment
Share on other sites

#include <GUIConstants.au3>
Dim $s_lnkPath
Dim $s_lnkURL

$s_lnkPath = FileSaveDialog("Select Shortcut Location",@DesktopDir,"Shortcuts (*.lnk)",16,"FF shortcut.lnk")
If @error Then Exit

;~ Started to do a simple inputbox, but then remembered that input boxes have a character limit of 254 characters.  Many urls can easily exceed 256 characters.
;~ $s_lnkURL = Inputbox("URL Input","Please input the URL that you would wish to have firefox open when the shortcut is double clicked:")

;Create GUI:
Dim $h_GUI, $h_Input, $h_OKBtn, $h_CpyFrmClipBtn, $msg
Dim $i_GUIWidth = 300
Dim $i_GUIHeight = 75
$h_GUI = GUICreate("Input",$i_GUIWidth,$i_GUIHeight,(@DesktopWidth - $i_GUIWidth)/2,(@DesktopHeight -$i_GUIHeight)/2,$WS_CAPTION + $WS_SYSMENU)

;Create Input Control:
Dim $i_InputLeft = 10
Dim $i_InputTop = 10
$h_Input = GUICtrlCreateInput("",$i_InputLeft ,$i_InputTop , $i_GUIWidth - (2*$i_InputLeft),25)

;Create OK Button:
Dim $i_OKWidth = 50
Dim $i_OKLeft = $i_GUIWidth - ($i_OKWidth + 10)
Dim $i_OKHeight = 23
Dim $i_OKTop = $i_GUIHeight - ($i_OKHeight + 10)
$h_OKBtn = GUICtrlCreateButton("&OK",$i_OKLeft,$i_OKTop,$i_OKWidth,$i_OKHeight)

;Create Copy URL From Clipboard Button:
Dim $i_CpyFrmClpWidth = 135
Dim $i_CpyFrmClpLeft = 10
Dim $i_CpyFrmClpHeight = 23
Dim $i_CpyFrmClpTop = $i_GUIHeight - ($i_CpyFrmClpHeight + 10)
$h_CpyFrmClipBtn = GUICtrlCreateButton("&Copy URL From Clipboard",$i_CpyFrmClpLeft,$i_CpyFrmClpTop,$i_CpyFrmClpWidth,$i_CpyFrmClpHeight)

;Set the OK Button as the Default Button:
GUICtrlSetState($h_OKBtn,$GUI_DEFBUTTON)

;Now that the GUI is complete, show the GUI to the user:
GUISetState()

While 1
    $msg = GUIGetMsg()
    Switch $msg
        Case $GUI_EVENT_CLOSE
            ;The user requested the program close and the script will now exit
            Exit
        Case $h_OKBtn
            If GUICTrlRead($h_Input) <> "" Then
                $s_lnkURL = GUICtrlRead($h_Input)
                Exitloop
            Else
                Msgbox(48,"Error","You didn't input any text.")
            EndIf
        Case $h_CpyFrmClipBtn
            GUICtrlSetData($h_Input,ClipGet())
    EndSwitch
WEnd

GUIDelete($h_GUI)

;FileCreateShortcut ( "file", "lnk" [, "workdir" [, "args" [, "desc" [, "icon" [, "hotkey" [, icon number [, state]]]]]]] )
If FileCreateShortcut(@UserProfileDir & "\Application Data\Microsoft\Internet Explorer\Quick Launch\WXP\APP- Firefox Portable v2.0.0.3\FirefoxPortable.exe",$s_lnkPath,'','"'&$s_lnkURL&'"') Then
    MsgBox(64, 'Done!', "Shortcut was successfully created.",2)
Else
    MsgBox(16, 'Error!', "Shortcut was not created.")
EndIf

ExitoÝ÷ ج¶z-ÇjاÊاÊÜjKhi×H§^¶ªºC¢w·Þ«¨´Ë cºËZnÞ{azÇ+mg¨ºÖµêö±ç(ÛꮢݪºbØb²X§y«­¢+Ø5Í  ½à ØаÌäí½¹ÌÌìÌäì°ÅÕ½ÐíM¡½ÉÑÕÐÝÌÍÕÍÍÕ±±äÉѸÅÕ½Ðì°È¤

Near perfect script, thanks again! :)

Link to comment
Share on other sites

  • 3 weeks later...

#include <GUIConstants.au3>
Dim $s_lnkPath
Dim $s_lnkURL

$s_lnkPath = FileSaveDialog("Select Shortcut Location",@DesktopDir,"Shortcuts (*.lnk)",16,"FF shortcut.lnk")
If @error Then Exit

;~ Started to do a simple inputbox, but then remembered that input boxes have a character limit of 254 characters.  Many urls can easily exceed 256 characters.
;~ $s_lnkURL = Inputbox("URL Input","Please input the URL that you would wish to have firefox open when the shortcut is double clicked:")

;Create GUI:
Dim $h_GUI, $h_Input, $h_OKBtn, $h_CpyFrmClipBtn, $msg
Dim $i_GUIWidth = 300
Dim $i_GUIHeight = 75
$h_GUI = GUICreate("Input",$i_GUIWidth,$i_GUIHeight,(@DesktopWidth - $i_GUIWidth)/2,(@DesktopHeight -$i_GUIHeight)/2,$WS_CAPTION + $WS_SYSMENU)

;Create Input Control:
Dim $i_InputLeft = 10
Dim $i_InputTop = 10
$h_Input = GUICtrlCreateInput("",$i_InputLeft ,$i_InputTop , $i_GUIWidth - (2*$i_InputLeft),25)

;Create OK Button:
Dim $i_OKWidth = 50
Dim $i_OKLeft = $i_GUIWidth - ($i_OKWidth + 10)
Dim $i_OKHeight = 23
Dim $i_OKTop = $i_GUIHeight - ($i_OKHeight + 10)
$h_OKBtn = GUICtrlCreateButton("&OK",$i_OKLeft,$i_OKTop,$i_OKWidth,$i_OKHeight)

;Create Copy URL From Clipboard Button:
Dim $i_CpyFrmClpWidth = 135
Dim $i_CpyFrmClpLeft = 10
Dim $i_CpyFrmClpHeight = 23
Dim $i_CpyFrmClpTop = $i_GUIHeight - ($i_CpyFrmClpHeight + 10)
$h_CpyFrmClipBtn = GUICtrlCreateButton("&Copy URL From Clipboard",$i_CpyFrmClpLeft,$i_CpyFrmClpTop,$i_CpyFrmClpWidth,$i_CpyFrmClpHeight)

;Set the OK Button as the Default Button:
GUICtrlSetState($h_OKBtn,$GUI_DEFBUTTON)

;Now that the GUI is complete, show the GUI to the user:
GUISetState()

While 1
    $msg = GUIGetMsg()
    Switch $msg
        Case $GUI_EVENT_CLOSE
            ;The user requested the program close and the script will now exit
            Exit
        Case $h_OKBtn
            If GUICTrlRead($h_Input) <> "" Then
                $s_lnkURL = GUICtrlRead($h_Input)
                Exitloop
            Else
                Msgbox(48,"Error","You didn't input any text.")
            EndIf
        Case $h_CpyFrmClipBtn
            GUICtrlSetData($h_Input,ClipGet())
    EndSwitch
WEnd

GUIDelete($h_GUI)

;FileCreateShortcut ( "file", "lnk" [, "workdir" [, "args" [, "desc" [, "icon" [, "hotkey" [, icon number [, state]]]]]]] )
If FileCreateShortcut(@UserProfileDir & "\Application Data\Microsoft\Internet Explorer\Quick Launch\WXP\APP- Firefox Portable v2.0.0.3\FirefoxPortable.exe",$s_lnkPath,'','"'&$s_lnkURL&'"') Then
    MsgBox(64, 'Done!', "Shortcut was successfully created.",2)
Else
    MsgBox(16, 'Error!', "Shortcut was not created.")
EndIf

Exit
Knucklehead strikes again <sigh>!!!

I've tried _everything_ and it's just so frustrating. All I'm trying to do this morning is to switch which box comes up first. (It's rather "stumbly" to name the file first; easier to paste the URL first then worry about name of shortcut <g>.)

I moved code around and around but no matter what I do, the "naming link" prompts comes up before the "paste URL" input box <sigh>! There's something in this code I don't know about that is determining what comes up first as even changing the order didn't change anything (i.e., placing all $h_OKBtn after $h_CpyFrmClipBtn in various places did nothing to change order of appearance).

Thank you for any help in advance. I'll get this sucker AI code one of these days <grrr>! :)

Link to comment
Share on other sites

Just had to move the FileSaveDialog() with error handling so that it comes after the GUIDelete():

#include <GUIConstants.au3>
Dim $s_lnkPath
Dim $s_lnkURL

;~ Started to do a simple inputbox, but then remembered that input boxes have a character limit of 254 characters.  Many urls can easily exceed 256 characters.
;~ $s_lnkURL = Inputbox("URL Input","Please input the URL that you would wish to have firefox open when the shortcut is double clicked:")

;Create GUI:
Dim $h_GUI, $h_Input, $h_OKBtn, $h_CpyFrmClipBtn, $msg
Dim $i_GUIWidth = 300
Dim $i_GUIHeight = 75
$h_GUI = GUICreate("Input",$i_GUIWidth,$i_GUIHeight,(@DesktopWidth - $i_GUIWidth)/2,(@DesktopHeight -$i_GUIHeight)/2,$WS_CAPTION + $WS_SYSMENU)

;Create Input Control:
Dim $i_InputLeft = 10
Dim $i_InputTop = 10
$h_Input = GUICtrlCreateInput("",$i_InputLeft ,$i_InputTop , $i_GUIWidth - (2*$i_InputLeft),25)

;Create OK Button:
Dim $i_OKWidth = 50
Dim $i_OKLeft = $i_GUIWidth - ($i_OKWidth + 10)
Dim $i_OKHeight = 23
Dim $i_OKTop = $i_GUIHeight - ($i_OKHeight + 10)
$h_OKBtn = GUICtrlCreateButton("&OK",$i_OKLeft,$i_OKTop,$i_OKWidth,$i_OKHeight)

;Create Copy URL From Clipboard Button:
Dim $i_CpyFrmClpWidth = 135
Dim $i_CpyFrmClpLeft = 10
Dim $i_CpyFrmClpHeight = 23
Dim $i_CpyFrmClpTop = $i_GUIHeight - ($i_CpyFrmClpHeight + 10)
$h_CpyFrmClipBtn = GUICtrlCreateButton("&Copy URL From Clipboard",$i_CpyFrmClpLeft,$i_CpyFrmClpTop,$i_CpyFrmClpWidth,$i_CpyFrmClpHeight)

;Set the OK Button as the Default Button:
GUICtrlSetState($h_OKBtn,$GUI_DEFBUTTON)

;Now that the GUI is complete, show the GUI to the user:
GUISetState()

While 1
    $msg = GUIGetMsg()
    Switch $msg
        Case $GUI_EVENT_CLOSE
            ;The user requested the program close and the script will now exit
            Exit
        Case $h_OKBtn
            If GUICTrlRead($h_Input) <> "" Then
                $s_lnkURL = GUICtrlRead($h_Input)
                Exitloop
            Else
                Msgbox(48,"Error","You didn't input any text.")
            EndIf
        Case $h_CpyFrmClipBtn
            GUICtrlSetData($h_Input,ClipGet())
    EndSwitch
WEnd

GUIDelete($h_GUI)

$s_lnkPath = FileSaveDialog("Select Shortcut Location",@DesktopDir,"Shortcuts (*.lnk)",16,"FF shortcut.lnk")
If @error Then Exit

;FileCreateShortcut ( "file", "lnk" [, "workdir" [, "args" [, "desc" [, "icon" [, "hotkey" [, icon number [, state]]]]]]] )
If FileCreateShortcut(@UserProfileDir & "\Application Data\Microsoft\Internet Explorer\Quick Launch\WXP\APP- Firefox Portable v2.0.0.3\FirefoxPortable.exe",$s_lnkPath,'','"'&$s_lnkURL&'"') Then
    MsgBox(64, 'Done!', "Shortcut was successfully created.",2)
Else
    MsgBox(16, 'Error!', "Shortcut was not created.")
EndIf

Exit

- The Kandie Man ;-)

"So man has sown the wind and reaped the world. Perhaps in the next few hours there will no remembrance of the past and no hope for the future that might have been." & _"All the works of man will be consumed in the great fire after which he was created." & _"And if there is a future for man, insensitive as he is, proud and defiant in his pursuit of power, let him resolve to live it lovingly, for he knows well how to do so." & _"Then he may say once more, 'Truly the light is sweet, and what a pleasant thing it is for the eyes to see the sun.'" - The Day the Earth Caught Fire

Link to comment
Share on other sites

A minor suggestion, you may want to check the contents of the clipboard when you come in and prepopulate the URL field with the contents if it appears to be a URL. (I've done something similair but also retrieved the url target and parsed out the page title)

By far, the worst four letter word (swear word) out there has to be USER
Link to comment
Share on other sites

Just had to move the FileSaveDialog() with error handling so that it comes after the GUIDelete():

#include <GUIConstants.au3>
Dim $s_lnkPath
Dim $s_lnkURL

;~ Started to do a simple inputbox, but then remembered that input boxes have a character limit of 254 characters.  Many urls can easily exceed 256 characters.
;~ $s_lnkURL = Inputbox("URL Input","Please input the URL that you would wish to have firefox open when the shortcut is double clicked:")

;Create GUI: ...
Ah, I can see what you did. The line:
$s_lnkPath = FileSaveDialog("Select Shortcut Location",@DesktopDir,"Shortcuts (*.lnk)",16,"FF shortcut.lnk")
original in SciTE on line 5, you moved after:
GUIDelete($h_GUI)
, previously on line 60.

Thanks! I would never have figured that out on my own.

Cheers. :)

Link to comment
Share on other sites

A minor suggestion, you may want to check the contents of the clipboard when you come in and prepopulate the URL field with the contents if it appears to be a URL. (I've done something similair but also retrieved the url target and parsed out the page title)

Hi, thanks. It's not a pre-populated field, fortunately. Since just before invoking the script, I'm copying the URL, this thankfully isn't an issue. I copy the URL, launch script, paste URL in, then name shortcut.

Now even easier with this modified script! :)

Link to comment
Share on other sites

If this is only for URL shortcuts then you might also want to take a look at changing the *.lnk file type to *.url which is the default filetype for internetshortcut

George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

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...