Xcode project suddenly not working

all of a sudden, in the middle of working on a ASS project in x-code, it starts behaving very strangely. I’m pretty sure I didn’t change anything.

the problem is when I try to compile and run my Application. the main window for the application opens but X code is still the active application and the application that is supposedly running is not showing so in the dock. when I try to type in a text field in the main window of this ‘Ghost’ application the text is not visible in the textfield, but in x code’s log window :?

If I go to the build folder and launch the application manually it works fine, but I can’t really test it like this. Does anyone have any idea what is going on and what may be the cause of this strange behavior??
I have restarted twice, cleaned the targets, and trashed the x code preferences but the problem persists. I am about to fix permisions.
I also tried a backuup of the project which worked before, but it showed the same behavior :frowning:

thanks
:cry:

Forget all that, I fixed it. Re-installed developer tools, made a new project - pasted the old script dat into the new file, copied the nib file, all’s well.

how can I save a list as a paragraph in a text file and then read it back and convert it’s items into a list again? i cold do it with words but then if some items need to different amount of words in different paragraphs everything gets thrown off… I looked through the AppleScript language guide but from what I saw about coercing classes this is not possible. But surely there must be a way, and anyway that document seems very outdated to me…

thanks

Glad Xcode is working again.

Just coerce your list to a string of paragraphs, write the data, then read it in again as paragraphs:

set the_file to (((path to desktop) as string) & "some_file.txt")
set the_data to {"1", "2", "3"}

--convert the list to a string of paragraphs
set old_delim to AppleScript's text item delimiters
set AppleScript's text item delimiters to return
set the_data to the_data as string
set AppleScript's text item delimiters to old_delim
set with_appending to false
my write_to_file(the_file, the_data, with_appending)

set read_data to paragraphs of (read file the_file)
do shell script "rm " & (quoted form of POSIX path of the_file) --kill the file
return read_data

on write_to_file(the_file, the_data, with_appending)
	set the_file to the_file as file specification
	try
		open for access the_file with write permission
		if with_appending = false then set eof of the_file to 0
		write the_data to the_file starting at eof
		close access the_file
	on error the_error
		try
			close access the_file
		end try
	end try
end write_to_file

Jon

Ok, thought of that but wouldn’t it get a bit confusing if there are lot’s of listst?

(the data to record is a list of people and info about them, ie, email, name, dates etc)

what I was planning on doings is have a paragraph for each person in the list and then put each pice of data for that person in that paragraph, like this:

paragraph 1:
Arum Devereux arum@devil.com £0.00 cash 11272531-17244745-46222118 ankk-ck1h-3hga 9/March/2004

paragraph 2:
test dummy 1 testdummy@1.com £20.00 CC 11262531-17244745-46212118 amkk-ck1h-3gga 9/March/2004

paragraph 3:
test dummy 2 testdummy@2.com $10.00 cash 11241531-17244745-46212618 akoo-ck1h-3gma 9/March/2004

but if I have each item as a paragraph then don’t I have to have a separate text file for each record?

thanks

Well, you really should be using the lists of lists (or better yet, records) and then you could do something like this:

set the_file to (((path to desktop) as string) & "some_file.txt")
set the_data to {{"Arum", "Devereux", "arum@devil.com", "?0.00", "cash", "11272531-17244745-46222118", "ankk-ck1h-3hga", "9/March/2004"}, {"test", "dummy 1", "testdummy@1.com", "?20.00", "CC", "11262531-17244745-46212118", "amkk-ck1h-3gga", "9/March/2004"}, {"test", "dummy 2", "testdummy@2.com", "$10.00", "cash", "11241531-17244745-46212618", "akoo-ck1h-3gma", "9/March/2004"}}

--convert the list of lists to a string of tab delimited paragraphs
set old_delim to AppleScript's text item delimiters
set AppleScript's text item delimiters to tab
repeat with i from 1 to (count the_data)
	set (item i of the_data) to (item i of the_data) as string
end repeat
set AppleScript's text item delimiters to return
set the_data to the_data as string
set AppleScript's text item delimiters to old_delim
--the_data now looks like:
(*
"Arum    Devereux    arum@devil.com    ?0.00    cash    11272531-17244745-46222118    ankk-ck1h-3hga    9/March/2004
test    dummy 1    testdummy@1.com    ?20.00    CC    11262531-17244745-46212118    amkk-ck1h-3gga    9/March/2004
test    dummy 2    testdummy@2.com    $10.00    cash    11241531-17244745-46212618    akoo-ck1h-3gma    9/March/2004"
*)

--write it:
my write_to_file(the_file, the_data, false)

--read it back in:
set read_data to paragraphs of (read file the_file)

--convert it back to the original format:
set old_delim to AppleScript's text item delimiters
set AppleScript's text item delimiters to tab
repeat with i from 1 to (count read_data)
	set (item i of read_data) to (text items of (item i of read_data))
end repeat
set AppleScript's text item delimiters to old_delim

--kill the file:
do shell script "rm " & (quoted form of POSIX path of the_file)

return read_data
-->{{"Arum", "Devereux", "", "arum@devil.com", "?0.00", "cash", "11272531-17244745-46222118", "ankk-ck1h-3hga", "9/March/2004"}, {"test", "dummy 1", "testdummy@1.com", "?20.00", "CC", "11262531-17244745-46212118", "amkk-ck1h-3gga", "9/March/2004"}, {"test", "dummy 2", "testdummy@2.com", "$10.00", "cash", "11241531-17244745-46212618", "akoo-ck1h-3gma", "9/March/2004"}}

on write_to_file(the_file, the_data, with_appending)
	set the_file to the_file as file specification
	try
		open for access the_file with write permission
		if with_appending = false then set eof of the_file to 0
		write the_data to the_file starting at eof
		close access the_file
	on error the_error
		try
			close access the_file
		end try
	end try
end write_to_file

Or even better, as I’ve mentioned before, you can write any type of data to a file using AppleScript, not just text. Try using records. Keep you data as records, write it to a file as a list of records, read it back in as a list of records:

set the_file to (((path to desktop) as string) & "some_file.txt")
set the_data to {{first_name:"Arum", last_name:"Devereux", email_add:"arum@devil.com", payment:"?0.00", payment_method:"cash", id_1:"11272531-17244745-46222118", id_2:"ankk-ck1h-3hga", payment_date:"9/March/2004"}, {first_name:"test", last_name:"dummy 1", email_add:"testdummy@1.com", payment:"?20.00", payment_method:"CC", id_1:"11262531-17244745-46212118", id_2:"amkk-ck1h-3gga", payment_date:"9/March/2004"}, {first_name:"test", last_name:"dummy 2", email_add:"testdummy@2.com", payment:"$10.00", payment_method:"cash", id_1:"11241531-17244745-46212618", id_2:"akoo-ck1h-3gma", payment_date:"9/March/2004"}}
my write_to_file(the_file, the_data, false)

set read_data to (read file the_file as (class of the_data))

do shell script "rm " & (quoted form of POSIX path of the_file) --kill the file

return read_data
-->{{first_name:"Arum", last_name:"Devereux", email_add:"arum@devil.com", payment:"?0.00", payment_method:"cash", id_1:"11272531-17244745-46222118", id_2:"ankk-ck1h-3hga", payment_date:"9/March/2004"}, {first_name:"test", last_name:"dummy 1", email_add:"testdummy@1.com", payment:"?20.00", payment_method:"CC", id_1:"11262531-17244745-46212118", id_2:"amkk-ck1h-3gga", payment_date:"9/March/2004"}, {first_name:"test", last_name:"dummy 2", email_add:"testdummy@2.com", payment:"$10.00", payment_method:"cash", id_1:"11241531-17244745-46212618", id_2:"akoo-ck1h-3gma", payment_date:"9/March/2004"}}

on write_to_file(the_file, the_data, with_appending)
	set the_file to the_file as file specification
	try
		open for access the_file with write permission
		if with_appending = false then set eof of the_file to 0
		write the_data to the_file starting at eof as (class of the_data)
		close access the_file
	on error the_error
		try
			close access the_file
		end try
	end try
end write_to_file

Jon

jon, that has been really helpfull, thanks a lot. The top example is better in this case as it’s easier to write to the file manually if I have to. I have having an issue though (this delimiter stuff is new to me).
In the example you gave you had “the_data” as a list of three lists. But in this case I will only need to write one list to the file at a time. i tried to change the code to reflect this but it didn’t quite work, here is the code:

set the_file to (((path to desktop) as string) & "some_file.txt")
set the_data to {"Arum", "Devereux", "arum@devil.com", "£0.00", "cash", "11272531-17244745-46222118", "ankk-ck1h-3hga", "9/March/2004"}

--convert the list of lists to a string of tab delimited paragraphs 
set old_delim to AppleScript's text item delimiters
set AppleScript's text item delimiters to tab

set (the_data) to (the_data) as string

set AppleScript's text item delimiters to return
set the_data to the_data as string
set AppleScript's text item delimiters to old_delim
--the_data now looks like: 
(* 
"Arum     Devereux     arum@devil.com     £0.00     cash     11272531-17244745-46222118     ankk-ck1h-3hga     9/March/2004 
test     dummy 1     testdummy@1.com     £20.00     CC     11262531-17244745-46212118     amkk-ck1h-3gga     9/March/2004 
test     dummy 2     testdummy@2.com     $10.00     cash     11241531-17244745-46212618     akoo-ck1h-3gma     9/March/2004" 
 *)

--write it: 
my write_to_file(the_file, the_data, true)

--read it back in: 
set read_data to paragraphs of (read file the_file)

--convert it back to the original format: 
set old_delim to AppleScript's text item delimiters
set AppleScript's text item delimiters to tab
repeat with i from 1 to (count read_data)
	set (item i of read_data) to (text items of (item i of read_data))
end repeat
set AppleScript's text item delimiters to old_delim

--kill the file: 
--do shell script "rm " & (quoted form of POSIX path of the_file)

return read_data
-->{{"Arum", "Devereux", "", "arum@devil.com", "£0.00", "cash", "11272531-17244745-46222118", "ankk-ck1h-3hga", "9/March/2004"}, {"test", "dummy 1", "testdummy@1.com", "£20.00", "CC", "11262531-17244745-46212118", "amkk-ck1h-3gga", "9/March/2004"}, {"test", "dummy 2", "testdummy@2.com", "$10.00", "cash", "11241531-17244745-46212618", "akoo-ck1h-3gma", "9/March/2004"}} 

on write_to_file(the_file, the_data, with_appending)
	set the_file to the_file as file specification
	try
		open for access the_file with write permission
		if with_appending = false then set eof of the_file to 0
		write the_data to the_file starting at eof
		close access the_file
	on error the_error
		try
			close access the_file
		end try
	end try
end write_to_file

but then the data in the file turns out like this (after multiple writes to the file):

Arum	Devereux	arum@devil.com	£0.00	cash	11272531-17244745-46222118	ankk-ck1h-3hga	9/March/2004Arum	Devereux	arum@devil.com	£0.00	cash	11272531-17244745-46222118	ankk-ck1h-3hga	9/March/2004Arum	Devereux	arum@devil.com	£0.00	cash	11272531-17244745-46222118	ankk-ck1h-3hga	9/March/2004

(you may need to actually run the script and open the file in a text editor to see what I mean???).

So how do i get it to write a nice new paragraph each time I run the script.

Also, what should applescript’s delimiters be set to as default? they seem to be acting strangely and re-launching Script editor and X code doesn’t seem to reset them…

thanks,

arum

This should get you going (well, it is everything you need, actually). Anything more and I need to start charging. Really. AppleScript’s default text item delimiters should be “”.

property the_file : (((path to desktop) as string) & "some_file.txt")
property all_data : {}

my initialize_data()
set new_row to {"Arum", "Devereux", "arum@devil.com", "?0.00", "cash", "11272531-17244745-46222118", "ankk-ck1h-3hga", "9/March/2004"}
my add_row(new_row)
set new_row to {"test", "dummy 1", "testdummy@1.com", "?20.00", "CC", "11262531-17244745-46212118", "amkk-ck1h-3gga", "9/March/2004"}
my add_row(new_row)
set new_row to {"test", "dummy 2", "testdummy@2.com", "$10.00", "cash", "11241531-17244745-46212618", "akoo-ck1h-3gma", "9/March/2004"}
my add_row(new_row)
return all_data

on initialize_data()
	try
		my read_data()
	on error
		set all_data to {}
		my write_all_data()
	end try
end initialize_data

on add_row(the_row)
	my write_one_row(the_row)
	set end of all_data to the_row
end add_row

on read_data()
	set all_data to paragraphs of (read file the_file)
	set old_delim to AppleScript's text item delimiters
	my atid(tab)
	repeat with i from 1 to (count all_data)
		set (item i of all_data) to (text items of (item i of all_data))
	end repeat
	my atid(old_delim)
end read_data

on write_all_data()
	--reset the contents of the file to "":
	my write_to_file(the_file, "", false)
	repeat with the_row in all_data
		my write_one_row(the_row)
	end repeat
end write_all_data

on write_one_row(the_row)
	set the_row to my convert_list_to_string(the_row, tab)
	my write_to_file(the_file, the_row & return, true)
end write_one_row

on convert_list_to_string(the_list, the_delim)
	set old_delim to AppleScript's text item delimiters
	my atid(the_delim)
	set the_list to the_list as string
	my atid(old_delim)
	return the_list
end convert_list_to_string

on write_to_file(the_file, the_data, with_appending)
	set the_file to the_file as file specification
	try
		open for access the_file with write permission
		if with_appending = false then set eof of the_file to 0
		write the_data to the_file starting at eof
		close access the_file
	on error the_error
		try
			close access the_file
		end try
	end try
end write_to_file

on atid(the_delim)
	set AppleScript's text item delimiters to the_delim
end atid

Jon