AutoHotkey Community

It is currently May 27th, 2012, 12:13 pm

All times are UTC [ DST ]




Post new topic Reply to topic  [ 9 posts ] 
Author Message
PostPosted: May 16th, 2011, 5:55 pm 
Offline
User avatar

Joined: March 1st, 2011, 12:46 am
Posts: 254
Hi everyone!
Here is a collection of functions that I use for my scripts in the "Lib" folder.

Files :
  • EmptyMem (by heresy) : Reduces the memory consumption of a process (original post)
  • Gdip (by tic) : Gdip standard library
  • GetFileEncoding : Returns the encoding of a file
  • GetProcessSize (by ton80) : Get the "Working set" memory consumption of the script (original post)
  • In : Checks if the variable is in the list or the array
  • Is : Checks if the var has a supported type, is a path or an url
  • R2A_Path : Converts a relative path to an absolute path
  • Run : More complete "Run" function
  • Scroll (by BoffinbraiN) : Accelerates the scrolling (original post)
All functions : Lib.zip

Thanks to : BoffinbraiN, heresy, MasterFocus, tic & ton80

_________________
Previously known as TomXIII
Image
Image


Last edited by R3gX on May 18th, 2011, 9:26 pm, edited 2 times in total.

Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: May 17th, 2011, 7:29 am 
hi R3gX

I've been looking for a copy url script for a long time

however I came across a similar script of yours from another member of this board, but i was unable to use it

maybe this is not what i am looking for but i am basically trying to copy absolute file path of a file that i select in explorer.

is this what your script does?


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: May 17th, 2011, 10:02 am 
Offline
User avatar

Joined: March 1st, 2011, 12:46 am
Posts: 254
Hi!

There is nothing in the collection that does what you want but I think this code might help :
Code:
^#c::                     ; Ctrl+Win+C
Selection := GetSelection()   ; Call the function to get the selection
MsgBox, % Selection            ; Display the selection
Return

GetSelection()
{ ; Get the list of the files/folders selected in Windows Explorer
   LastClipboard := ClipboardAll   ; Save the previous clipboard
   Clipboard := ""               ; Start off empty to allow ClipWait to detect when the text has arrived
   SendInput, ^c               ; Simulate the Copy hotkey (Ctrl+C)
   ClipWait, 2, 1               ; Wait 2 seconds for the clipboard to contain text
   Selection := Clipboard         ; Put the clipboard in the variable Selection
   Clipboard := LastClipboard      ; Restore the previous clipboard
   Return, Selection            ; Return the selection
}
I decided to use the Ctrl+Win+C hotkey but you can put "Selection := GetSelection()" inside another function or even a label.

For more informations :
- Clipboard : http://www.autohotkey.com/docs/misc/Clipboard.htm
- Sort : Might be usefull to sort the selection http://www.autohotkey.com/docs/commands/Sort.htm

_________________
Previously known as TomXIII
Image
Image


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: May 17th, 2011, 9:42 pm 
Offline

Joined: April 8th, 2009, 8:23 pm
Posts: 3036
Location: Rio de Janeiro - RJ - Brasil
R3gX, your Is function can be a bit improved.
Code:
Is(V,T) {
  If !( StrLen(V) & StrLen(T) )
    Return
  If ( T = "URL" )
    Return RegExMatch( V , "^(ftp|https?)://" )
    ; or maybe something like "((mailto\:|(news|(ht|f)tp(s?))\://){1}\S+)"
    ; reference: http://regexlib.com/REDetails.aspx?regexp_id=37
  If ( T = "PATH" )
    Return FileExist(V)
  If V is %T%
    Return 1
}

It also reminds me of my Type Functions.

EDIT: I used the wrong bitwise operator. Corrected.

_________________
"Read the manual. Read it again. Search the forum.
Try something before asking. Show what you've tried.
"
Image
Antonio França
My stuff: Google Profile


Last edited by MasterFocus on May 17th, 2011, 9:53 pm, edited 1 time in total.

Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: May 17th, 2011, 9:46 pm 
Offline
User avatar

Joined: March 1st, 2011, 12:46 am
Posts: 254
Thanks you MasterFocus! I will update the function tomorrow.

_________________
Previously known as TomXIII
Image
Image


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: May 18th, 2011, 8:40 pm 
Offline
User avatar

Joined: March 1st, 2011, 12:46 am
Posts: 254
The Is.ahk is updated with the regex given by MasterFocus to match an url.
Thanks MasterFocus!

I added a link to a zip file that contains every functions.

_________________
Previously known as TomXIII
Image
Image


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: May 19th, 2011, 2:36 am 
Offline

Joined: April 8th, 2009, 8:23 pm
Posts: 3036
Location: Rio de Janeiro - RJ - Brasil
R3gX, did you notice the other improvements? Just wondering.
(I'm supposing you only noticed the regex since I colored it...
Sometimes I do read quickly and notice only colored stuff hehe)

_________________
"Read the manual. Read it again. Search the forum.
Try something before asking. Show what you've tried.
"
Image
Antonio França
My stuff: Google Profile


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: May 19th, 2011, 9:19 am 
Offline
User avatar

Joined: March 1st, 2011, 12:46 am
Posts: 254
@MasterFocus : Actually, ... no!
Quote:
Sometimes I do read quickly and notice only colored stuff hehe
Me too!
But now I noticed that you've :
- changed the first evalution
- deleted the "Else" and the last "Return"
- renamed Value > V and Type > T

Without the first evaluation and the regex, is there any real improvements?
I'm just asking, I don't judge!

_________________
Previously known as TomXIII
Image
Image


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: May 20th, 2011, 4:36 am 
Offline

Joined: April 8th, 2009, 8:23 pm
Posts: 3036
Location: Rio de Janeiro - RJ - Brasil
Since !Type would be fine if "0" was passed, I suppose the following checks are better:
Code:
If StrLen(x)<1
If (x="") ; or maybe (x=="")

I did not benchmark these, so I can't provide any further information on which is "better".

Removing the Elses and renaming the variables was just to make the code shorter and easier to understand.
Personally, the code seems "messy" to me with all those Elses.
Note: yes, I know the shortest code is not always the most understandable, but that's not the case here

_________________
"Read the manual. Read it again. Search the forum.
Try something before asking. Show what you've tried.
"
Image
Antonio França
My stuff: Google Profile


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

All times are UTC [ DST ]


Who is online

Users browsing this forum: fincs and 9 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