AutoHotkey Community

It is currently May 26th, 2012, 3:42 pm

All times are UTC [ DST ]




Post new topic Reply to topic  [ 8 posts ] 
Author Message
PostPosted: March 17th, 2009, 1:03 am 
Offline

Joined: June 26th, 2007, 4:12 pm
Posts: 43
Hello, is there anyway to automate creating a shortcut for a selected file and sending the shortcut to the desktop? I've been looking at FileCreateShortcut but need to figure out a way to grab the information about which file is selected to use as the target parameter.

Thanks

CaH


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: March 17th, 2009, 1:50 am 
sending "Ctrl+C" will copy the file to the clipboard,
the built in var clipboard will contain the full-path of this file then.


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: March 17th, 2009, 3:31 pm 
Offline

Joined: June 26th, 2007, 4:12 pm
Posts: 43
Z_Gecko wrote:
sending "Ctrl+C" will copy the file to the clipboard,
the built in var clipboard will contain the full-path of this file then.

Thanks, copying the file to get the file name seems to be a last resort. Suppose I wanted to make a short cut for a disc image file. I'd end up copying gigabytes to get a name. I found a partial solution by resorting to send keys:
Code:
;click right
send nn
send {right}
send {down 4}
send {enter}

This will create a shortcut from windows explorer but when I try to run it using a file on the desktop it seems to crash. Could that be because I'm using a limited account rather than an admin account? But if I do the same actions without autohotkey I can get a shortcut. Can anyone think of anything else to try?

Thanks,

CaH


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: March 18th, 2009, 9:28 pm 
Offline

Joined: November 4th, 2008, 9:23 am
Posts: 1045
FYI, when you copy a file, you don't copy the file contents to memory - it only copies the name. So, you won't copy gigabytes to get a name. Another way uses ControlGet with suboption Focus or Selected (not sure which, seen it done, but never have used it myself.

To make a shortcut, check out FileCreateShortcut.

_________________
As always, if you have any further questions, don't hesitate to ask.

Add OOP to your scripts via the Class Library. Check out my scripts.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: March 18th, 2009, 10:51 pm 
Offline

Joined: June 26th, 2007, 4:12 pm
Posts: 43
animeaime wrote:
FYI, when you copy a file, you don't copy the file contents to memory - it only copies the name. So, you won't copy gigabytes to get a name.

Thanks, so do you mean if I avoid using ctr+v and clear the contents of the clipboard after the operation there should be no problem?

CaH


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: March 19th, 2009, 12:04 am 
Offline

Joined: November 4th, 2008, 9:23 am
Posts: 1045
Knowbodynow wrote:
Thanks, so do you mean if I avoid using ctr+v and clear the contents of the clipboard after the operation there should be no problem?

Correct, or, better yet, you can restore the previous contents - so it doesn't interfer with what's already there. The function below just merges the examples from Clipboard and ClipboardAll. I tested it by coping some data in paint, then using the hotkey; it restored the previous data with no problems. Thanks for this idea - I have a new function to add to my library :D.

Code:
#F9::
{
    UseClipboard(MyVar)

    MsgBox, % "You just copied: " . MyVar
    return
}

UseClipboard(ByRef OutputVar)
{
    ; Save the entire clipboard to a variable of your choice.
    ClipSaved := ClipboardAll

    ; Start off empty to allow ClipWait to detect when the text has arrived.
    Clipboard =
   
    Send, ^c
   
    ; Wait for the clipboard to contain text.
    Clipwait
   
    ; Saves Clipboard contents (to be returned ByRef)
    OutputVar := Clipboard
   
    ; Restore the original clipboard. Note the use of Clipboard (not ClipboardAll).
    Clipboard := ClipSaved
}

_________________
As always, if you have any further questions, don't hesitate to ask.

Add OOP to your scripts via the Class Library. Check out my scripts.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: March 21st, 2009, 4:54 am 
Offline

Joined: June 26th, 2007, 4:12 pm
Posts: 43
Great! I was able to use your idea to automatically create shortcuts on the all users desktop by adding two lines after the OutputVar line:

Code:
    ; Saves Clipboard contents (to be returned ByRef)
    OutputVar := Clipboard
    FileCreateShortcut, %Clipboard%, %Clipboard%.lnk,
    FileMove, %Clipboard%.lnk, %A_DesktopCommon%

Thanks very much,

CaH


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: March 21st, 2009, 5:28 am 
Offline

Joined: November 4th, 2008, 9:23 am
Posts: 1045
Just to let you know, the clipboard contents are returned via the ByRef value - so you don't need to change the function to use what's on the clipboard.

Code:
UseClipboard(FileName)
FileCreateShortcut, %FileName%, %FileName%.lnk,
FileMove, %FileName%.lnk, %A_DesktopCommon%


This allows using the same function for all your clipboard needs.

_________________
As always, if you have any further questions, don't hesitate to ask.

Add OOP to your scripts via the Class Library. Check out my scripts.


Report this post
Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 8 posts ] 

All times are UTC [ DST ]


Who is online

Users browsing this forum: DataLife, notsoobvious and 13 guests


You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Powered by phpBB® Forum Software © phpBB Group