Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

Corrado33

macrumors member
Original poster
Sep 2, 2008
62
0
So I'm working with database events now, and basically I want to ask the user for input so that that input can be put into a database field, however from what I can see, you are not allowed to get user input inside of a tell "Database Events".

How can I get around this?

Also, does anybody have a simple program to display the heirarchy of a database? So I can actually see if it's working or not? For the life of me I can't figure out how to display anything from a database (because of the "No User Action Allowed" thing).

Here is my code.

Code:
(*Starting non-important variables*)
set loop1 to 0
set loop2 to 0
(*END OF VARIABLES*)


set theDBpath to POSIX path of "Macintosh HD:Users:#####:Desktop:Database:storedapps.dbev"
tell application "Database Events"
	launch
	open database theDBpath
	tell database "storedapps"
		set recordcount to (count records)
	end tell
end tell

tell application "Finder"
	set currentapps to the name of every process whose visible is true
end tell

tell application "Database Events"
	tell database "storedapps"
		repeat with loop1 from 1 to the length of currentapps
			repeat with loop2 from 1 to recordcount
				if item loop1 of currentapps = record loop2 then
					display dialog "Found One"
				else
					make new record with properties {name:item loop1 of currentapps}
					set usedfor to display dialog "What is this program used for?" default answer "Something Awesome"
					tell record (item loop1 of currentapps)
						make new field with properties {name:"Uses", value:usedfor}
					end tell
				end if
			end repeat
		end repeat
	end tell
end tell

Honestly I don't know if any of this is working because I can't see the database.... :p But it will run whenever I take out this line...

Code:
set usedfor to display dialog "What is this program used for?" default answer "Something Awesome"

When I try to run it with that line in it, I get this error...
Database Events got an error: No user interaction allowed.
for the line specified directly above this.

Anybody know a way around it?
 
You're going to have to rewrite it with the display dialog line outside the tell block for Database Events.

Also, double check your double repeat loops. Let's say you've got five processes running: Camino, Mail, AppleScript Editor, Pages and Bean. Your database has Numbers, Safari, iCal and TextEdit.

Camino ≠ Numbers, so it makes a new record
Camino ≠ Safari, so it makes a new record
Camino ≠ iCal, so it makes a new record ... and so on.

Let's say your database does have Camino, Numbers, Safari, iCal and TextEdit.

Camino = Camino, so it skips.
but Camino ≠ Numbers, so it makes a new record, and so on.

You'd be better off doing something like:

Code:
set recordsToAdd to {}
set notHere to true
	repeat with loop1 from 1 to the length of currentapps
		repeat with loop2 from 1 to recordcount
			if item loop1 of currentapps = record loop2 then
				set notHere to false
				exit repeat
			end if
		end repeat
		if notHere = true then
			set recordsToAdd to recordsToAdd & item loop1 of currentapps
		end if
	end repeat

After you finish these loops, you can end your tell block, then have a repeat loop to go through recordsToAdd, polling the user for what the apps do, saving that data in another list variable; let's call it, whatUserSaid.

Then you create another Database Events tell block, loop through your first list variable for your record names. The same location in whatUserSaid will be the data the user entered into display dialog.

mt
 
You're going to have to rewrite it with the display dialog line outside the tell block for Database Events.

Camino ≠ Numbers, so it makes a new record
Camino ≠ Safari, so it makes a new record
Camino ≠ iCal, so it makes a new record ... and so on.

Yeah I figured the first thing (which should be that difficult cause I can just maybe copy my database into a couple temp lists then display and edit them... maybe). And I did eventually figure the second thing out... bad programming lol. But thanks for the help.

Anybody know WHY we can't have display dialog lines inside the Database Events tell block?
 
Two things:

One, Database Events has no user interface, so it can't process UI requests, which leads to:

Two, when you tell an application to do something, Applescript expects it to be able to do it. Here, AS is a bit different than one of its antecedents, HyperCard, which would just send a message up through its hierarchy until something understood the message.

However, you can do this:

Code:
tell application "Database Events"
	tell me to display dialog "Hello, world"
end tell

If you are in a jam and you need to display a dialog, you can just redirect the tell outside the tell "Database Events" block.

mt
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.