AutoHotkey Community

It is currently May 27th, 2012, 3:55 am

All times are UTC [ DST ]




Post new topic Reply to topic  [ 10 posts ] 
Author Message
PostPosted: June 5th, 2009, 9:54 pm 
Offline

Joined: March 27th, 2009, 12:46 pm
Posts: 76
Location: Dublin, IE
I was searching for some more things to do with Launchy, the open source keystroke launcher, and I came across an old Lifehacker article explaining how to update your Twitter status using Launchy, curl and a batch script.

I don't like using using curl, so I made a script instead using httpQuery.

DIRECTIONS
    1. Save the twit.ahk script to a directory.

    2. Enter your Twitter UserName and Password into the script.
Code:
UserName := "UserName"
Password := "Password"

    3. Add the directory to Launchy's Catelog and add *.ahk to the extensions

    Image

    4. Type twit in the Launchy bar and then press Tab and type your Twitter status.

    Image

    5. Voilà

    Image

twit.ahk
Code:
; ==============================================================================
; NAME:         twit.ahk
; VERSION:      v0.1.0
; DESCRIPTION:  Update Twitter status via Launchy
;
; AUTHOR:       Voltron43
; HOMEPAGE:     http://autohotkey.net/~Voltron43
; ==============================================================================
;
; ---Construct Status message from passed parameters
Loop, %0%
    Status := A_Index = 1 ? %A_Index% : Status " " %A_Index%

; ---Check to make sure Status is shorter than 140 characters
If StrLen(Status) > 140
{
    MsgBox, 32,,Status is too long!
    ExitApp
}
UserName := "UserName"
Password := "Password"
URL := "http://" UserName ":" Password "@twitter.com/statuses/update.xml?"
POSTdata := "status=" Status
length := httpQUERY(buffer:="",URL,POSTdata)
VarSetCapacity(buffer, -1)

; ---Check for error
If buffer contains status
    MsgBox, 32,, Status Update Complete!
Else
    MsgBox, 32,, Twitter Error!

#Include httpQuery.ahk

_________________
My Scripts


Report this post
Top
 Profile  
Reply with quote  
 Post subject: Error
PostPosted: May 10th, 2011, 8:34 am 
I have downloaded the httpQuery.ahk too for the include directive. Messagebox throws a twitter error, I wonder why! Inspite of typing in the status in launchy. Strangely, It is going into the if condition if I exceed the 140 limit but if it is less, the buffer is not getting filled with the status. Please help me.


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

Joined: May 18th, 2010, 3:10 pm
Posts: 1179
Location: Sweden
My guess is that Twitter only supports oAuth. Octal said in this post that he is working on a solution.

As for me, Tweeting is one of the more useful things that I would like to integrate directly in front of my nose, instead of having to go to a website to do it.

_________________
~sumon Appifyer AHK Nova halted Recommended: AHK_L (Why?)


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

Joined: October 13th, 2009, 10:09 pm
Posts: 1389
Hmm, interesting...
If this works I'd like to integrate it in my Accessor launcher in 7plus,
I suggest using COM for sending the data though. There should be an example for using the COM interface in the COM reference thread I think.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: July 5th, 2011, 4:59 am 
Offline

Joined: April 1st, 2011, 6:36 am
Posts: 63
Location: California
Hmmmm This is very interesting. I was wondering if anyone could explain to me how the first few lines of code (specifically the loop with %0%) works? I understand that it takes whatever you typed into launchy and saves it as "status" but i cant figure out how it goes about doing that. Very useful script. Thanks Voltron43


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: July 5th, 2011, 9:36 am 
@Sky:
The script is very simple, I'll explain it to you in the comments:
Code:
; ==============================================================================
; NAME:         twit.ahk
; VERSION:      v0.1.0
; DESCRIPTION:  Update Twitter status via Launchy
;
; AUTHOR:       Voltron43
; HOMEPAGE:     http://autohotkey.net/~Voltron43
; ==============================================================================
;
; ---Construct Status message from passed parameters
Loop, %0% ; variable 0 contains the number of parameters passed to the script, e.g. the numbers of words --> loop that often
    Status := A_Index = 1 ? %A_Index% : Status " " %A_Index% ; put the different words into a single string

; ---Check to make sure Status is shorter than 140 characters
If StrLen(Status) > 140
{
    MsgBox, 32,,Status is too long!
    ExitApp
}
UserName := "UserName"
Password := "Password"
URL := "http://" UserName ":" Password "@twitter.com/statuses/update.xml?" ; creates the url with username and password
POSTdata := "status=" Status ; this will be sent to the above url
length := httpQUERY(buffer:="",URL,POSTdata) ; send the status to twitter
VarSetCapacity(buffer, -1) ; convert the returned data to a string

; ---Check for error
If buffer contains status
    MsgBox, 32,, Status Update Complete!
Else
    MsgBox, 32,, Twitter Error!

#Include httpQuery.ahk

Just write back if you have further questions.


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: July 5th, 2011, 5:18 pm 
Offline

Joined: April 1st, 2011, 6:36 am
Posts: 63
Location: California
Thanks nfl!
so I was wondering, is variable 0 sort of like a predefined variable used by launchy? I dont see it defined anywhere in the script. also for the starust part I understand that if %A_index%(word) = 1 then the status would be %A_index% because there was only 1 word. but if %A_index% is more than 1, how does status " " %A_index% join the words? is it looping and adding a space in between the %A_index%'s(word)?
sorry for the noobish questions. And thank you very much nfl for explaining the rest of the script to me :) it was very helpful and im grateful


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: July 5th, 2011, 5:32 pm 
Offline

Joined: October 13th, 2009, 10:09 pm
Posts: 1389
0 is the number of command line arguments, 1 is the first one, 2 the second,...
For further information please refer to the help file.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: July 5th, 2011, 6:57 pm 
Sky wrote:
is variable 0 sort of like a predefined variable used by launchy? I dont see it defined anywhere in the script.

No, it's the number of arguments passed to the script. Look in the help file under "parameters passed into a script".

Sky wrote:
but if %A_index% is more than 1, how does status " " %A_index% join the words? is it looping and adding a space in between the %A_index%'s(word)?

It is joining the words, because there is
Code:
status := status " " %A_Index%

You could write the block like this:
Code:
Loop, %0% ; variable 0 contains the number of parameters passed to the script, e.g. the numbers of words --> loop that often
{
   if (A_Index = 1)
      Status := %A_Index%
   else
      Status := Status " " %A_Index%
      ; or my preferred way
      ; Status .= " " %A_Index%
}


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: July 5th, 2011, 8:29 pm 
Offline

Joined: April 1st, 2011, 6:36 am
Posts: 63
Location: California
thanks fragman and nfl! thanks to you guys ill be able to work on some cool scripts with launchy. hopefully the community will find them useful :p


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

All times are UTC [ DST ]


Who is online

Users browsing this forum: No registered users and 25 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