This line seems to fail in Xcode on my 10.4.11 laptop.
tell application endresult to quit
It is supposed to quit the application who’s name is in the variable ‘endresult’. Instead it quits itself.
The bit of code I’m using is as follows:
set command to every word of (the contents of text field "Input Box" as text) as list
if item 1 of command is "quit" then
try
set endresult to item 2 of command
repeat with i from (3) to 20
try
set endresult to endresult & " " & item i of command as text
on error e
exit repeat
end try
end repeat
tell application endresult to quit
end try
tell application Current_Application to quit
end if
The app compiles just fine and no errors are returned.
Also, when replacing the line with a ‘display dialog endresult’, I get the name of the app I typed in.
Any help would be appreciated. I’m going to start writing the rest of this thing… :lol:
Hi,
the problem might be, that endresult is not only the name of the application, it’s a space delimited string of the words of the text field.
I don’t know the context but you should take only the second item of command.
Here a more reliable version without try and error
set command to words of (get string value of text field "Input Box")
if item 1 of command is "quit" then
set theApplication to item 2 of command
set {TID, text item delimiters} to {text item delimiters, space}
set endresult to items 2 thru -1 of command as text
set text item delimiters to TID
quit application theApplication
end if
By the way, all coercions in your original script are useless
the contents of text field "Input Box" as text
contents of text fields are always text
set command to every word of (the contents of text field "Input Box" as text) as list
words are always a list
item i of command as text
as contents of a text field is text the items are also text

Thanks for the reply.
I must say, I didn’t realize that words are items too. But the problem is that certain applications have more than one word names.
Quartz Composer
Address Book
Script Editor
This is why I tried to get every word except the first.
The idea is that i type ‘quit address book’ and said app will quit. Insisting that it’s the text returned of endtext does not work.
then this might be more reliable
set bundle to missing value
set command to "quit Address Book"
if command starts with "quit" then
set theApp to text ((offset of space in command) + 1) thru -1 of command
tell application "System Events"
if exists process theApp then set bundle to bundle identifier of process theApp
end tell
if bundle is not missing value then quit application id bundle
end if
Ok, a little bit of fiddling to make it ‘work’ and I get this:
set command to (the contents of text field "Input Box" as text)
if command is "quit" then
tell application Current_Application to quit
else if command starts with "quit" then
set theApp to text ((offset of space in command) + 1) thru -1 of command
tell application "System Events"
if exists process theApp then set thebundle to bundle identifier of process theApp
end tell
quit application id thebundle
end if
The error?
Also, while I’m at it, how can I get the system sound volume level on a scale of 0-7 as you would set it? volume settings and volume don’t seem to work…
With volume settings I get the output as <> which I presume would be a volume list.
With volume I get the error ‘Can’t make «class volL» of window “Input Window” into type reference. (-1700)’
Smile coupons exchanged for answers.
please
set command to string value of text field "Input Box"
With volume I get the error ‘Can’t make «class volL» of window “Input Window” into type reference. (-1700)’
this looks like you have a general tell window “Input Window” for the whole part of the script.
It’s recommended to use tell blocks only for the affected lines.
Are you using Tiger? AFAIK the property bundle identifier in System Events is introduced in Leopard
YIPE! So simple??? I feel like I could punch myself.
Thanks for your patience. I’ve only recently started using xcode at all for my scripting.
OK, This is what I re-wrote it all to:
if the name of theObject is "Do." then
tell window "Input Window" to set command to string value of text field "Input Box"
if command is "quit" then
if Current_Application is "me" then
quit
else
tell application Current_Application to quit
end if
else if command starts with "quit" then
set theApp to text ((offset of space in command) + 1) thru -1 of command
tell application "System Events"
if exists process theApp then set thebundle to bundle identifier of process theApp
end tell
quit application id thebundle
else if command starts with "volume" then
try
set volume (the last character of command)
end try
set the contents of text field "Output" to "Application: " & Current_Application & return & "Volume: " & volume
end if
end if
and I get two errors.
Command: Error:
quit textedit System Events got an error: Can’t make «class bnid» of process “textedit” into type reference. (-1700)
volume Can’t make «class volL» into type reference. (-1700)
Groan.
read the dictionary, set volume has some parameters and the value must be number (or integer)
set volume
set volume (verb)Set the sound output and/or input volume (from the Miscellaneous Commands suite, defined in StandardAdditions.osax)
command syntax
set volume number ¬
output volume integer ¬
input volume integer ¬
alert volume integer ¬
output muted boolean
parameters
Parameter
Required
Type
Description
direct parameter optional number the sound output volume, a real number from 0 to 7 (This parameter is deprecated; if specified, all other parameters will be ignored.)
alert volume optional integer the alert volume, an integer from 0 to 100
input volume optional integer the sound input volume, an integer from 0 to 100
output muted optional boolean Should the sound output be muted?
output volume optional integer the sound output volume, an integer from 0 to 100
That part works fine. Getting the volume doesn’t.
there is no code to get the volume in this thread
I was hoping this line would work.
set the contents of text field “Output” to "Application: " & Current_Application & return & "Volume: " & volume
But I need something more refined… like…
set the contents of text field “Output” to "Application: " & Current_Application & return & "Volume: " & output volume of (get volume settings)
or, for the effect I wanted,
tell window “Input Window” to set the contents of text field “Output” to "Application: " & Current_Application & return & "Volume: " & (round ((output volume of (get volume settings)) / 100) * 7)
At least that part works… now to get back to the quitting… tomorrow. G’night!