If, variables and text

Hey all :smiley:
I am making a command prompt type thing and i am having some problems:


set _com to text returned of (display dialog ">>:" default answer "quit Dock" buttons {">"} default button 1)

if _com begins with "quit" then
	(* Execute my next questions code here *)
else
	display alert "Command Not Found!" message "\"" & _com & "\" Is not a valid command"
end if

so far so good, but what i need to be able to do now is get applescript to read the variable again and skip out the word quit then set the answer to another variable
Like this: (not real code!)


set _com to text returned of (display dialog ">>:" default answer "quit Dock" buttons {">"} default button 1)

if _com begins with "quit" then
	remove text "quit" from variable _com
       tell application _com to quit
else
	display alert "Command Not Found!" message "\"" & _com & "\" Is not a valid command"
end if

great if you can help me :smiley:

Hi,

try this

set _com to text returned of (display dialog ">>:" default answer "quit Dock" buttons {">"} default button 1)

if _com begins with "quit" then
	set _com to text 6 thru -1 of _com
	tell application "System Events" to if exists process _com then -- this checks if the process is running
		tell application _com to quit
	end if
else
	display alert "Command Not Found!" message "\"" & _com & "\" Is not a valid command"
end if

Hi Captainhams,

It’s not a good idea to have the user type in applications name. It’s better to have the user choose the app. Here’s an example:


tell application "System Events"
	set app_list to name of every process whose visible is true
end tell
set user_apps to choose from list app_list with multiple selections allowed
if user_apps is false then return
repeat with this_app in user_apps
	try
		tell application this_app to quit
	end try
end repeat

Note that some applications don’t have the same name as their process, but it’s rare.

gl,

Firefox is a notable example though (ā€œfirefox-binā€).

Hi Bruce,

That is a popular one. The script needs to be modified.

gl,

Something like this:


tell application "System Events"
	set app_list to name of every process whose visible is true
end tell
set user_apps to choose from list app_list with multiple selections allowed
if user_apps is false then return
repeat with this_app in user_apps
	tell application "System Events"
		set app_ref to (file of first process whose name is this_app) as string
	end tell
	tell application app_ref to quit
end repeat

gl,

i just get the error: System Events got an error: Can’t make application ā€œFinderā€ into type reference.

System Events threw the error, so try moving that line outside of the System Events tell block.

You can persue your idea forever, but I tell you, if entering commands and parameters is what you want, then you might just as well use Terminal. If you want to make an AppleScript ide, then it’s not worth the trouble. On top of that, you already have one that is much more powerful then just quitting apps. It even has syntax checks!

Some other apps have syntax checks also, like bbedit, Tex-Edit Plus, Smile, etc. (beyond the freeware and partial).

Personally, trying to build your own ide with AppleScript is pretty useless in my opinion and is just a waste of time.

gl,

I take that back. I was trying to build a python ide in AppleScript. It’s ok, but there are many hurdles. I don’t like the MacPython ide, but it is much better than anything you could write with AppleScirpt, not to mention speed.

The secret to speed with AppleScript, is knowing text manipulation. Especially is you have a lot of data; you want to deal with text because lists just can’t hack it.

gl,

Hi,

I have never found a good answer to this question which is the sticking point in creating a good database. What is the best way to make key value pairs with AppleScirpt in a text file. What I do is store the values in a list and store the keys in a table by blocks.So say you wanted to find the millionth block, you would search for the key with offset of. After you get the offset you just divide by the length of the block. Anybody know a faster way to search?

gl,