AutoHotkey Homepage AutoHotkey Community
Let's help each other out
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Get the Base name of the running script

 
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Scripts & Functions
View previous topic :: View next topic  
Author Message
Tasman



Joined: 20 May 2006
Posts: 21

PostPosted: Sat May 20, 2006 7:41 pm    Post subject: Get the Base name of the running script Reply with quote

This is a very simple function that returns the base name (ie. the name of the script without the extention) for use by for instance ini scripts.
This way if the name of the main script or exe is changed a corresponding ini file can be created/used, avoiding errors.

Just in case anybody is wondering why I am posting small trivialities like this, it's that I am in the process of writing a minimalist shell based on AHK
and these are functions used in it and I thought they might come in handy by others.

I'll be posting more stuff in the next few days just do a search for Tasman (runbox replacement, volume replacement etc., things normally handled by explorer)

Code:

dbase := getscriptname() ; get the base name of this program without the extension
ini = %A_ScriptDir%\%dbase%.ini ; and create the name of, for instance an ini file to use with this script.

MsgBox, %ini%

getscriptname(){
   dbase = %A_ScriptName%
   Length := StrLen(A_ScriptName)-4
   StringLeft, dbase, A_ScriptName, Length
   return %dbase%
}


I have a working version of the shell running on my own computer but its not ready for the primelight yet. You need to be carefull with shells, if you mess up you might not be able to get windows running again.
A lot of testing remains before I post all of it.
Back to top
View user's profile Send private message
SKAN



Joined: 26 Dec 2005
Posts: 6264

PostPosted: Sat May 20, 2006 7:57 pm    Post subject: Re: Get the Base name of the running script Reply with quote

Dear Tasman, Smile

Tasman wrote:
This is a very simple function that returns the base name (ie. the name of the script without the extention) for use by for instance ini scripts.
This way if the name of the main script or exe is changed a corresponding ini file can be created/used, avoiding errors.


Nice idea.. However it can be shortened to

Code:
GetScriptName(){
StringTrimRight,Name, A_ScriptName, 4
Return Name
}


... and I feel this is better version :

Code:
GetScriptName(){
SplitPath, A_ScriptFullPath,,,,Name,
Return Name
}

Quote:
I'll be posting more stuff in the next few days just do a search for Tasman (runbox replacement, volume replacement etc., things normally handled by explorer)

I have a working version of the shell running on my own computer but its not ready for the primelight yet. You need to be carefull with shells, if you mess up you might not be able to get windows running again.
A lot of testing remains before I post all of it.


Sounds interesting! .. Will await it.

Regards, Smile
_________________
Back to top
View user's profile Send private message
Tasman



Joined: 20 May 2006
Posts: 21

PostPosted: Sat May 20, 2006 8:54 pm    Post subject: Reply with quote

Thanks for the tip Goyyah
Love it when I can do the same with less code.
Changed my other submission accordingly (a simple runbox).
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Scripts & Functions All times are GMT
Page 1 of 1

 
Jump to:  
You can post new topics in this forum
You can reply to topics in this forum


Powered by phpBB © 2001, 2005 phpBB Group