Hello all,
I have an applescript studio app and i need to save the datasource from my table and some variables. What is the easy way to do this so that when i load the app the data will appear in my table from entering it the last time i used the app? Would i have to write to the preference file or can it be stored within the script somehow?
Thanks!!
OK here is my script. I need to save serversDataSource so i can reload them when i start me app. Can anyone help?#$@%^
property serversDataSource : null
on clicked theObject
if name of theObject is equal to "addBtn" then
-- Add a new server
if contents of text field "serverTXT" of window "with" is equal to "" then
display dialog "Please enter a Server/Share Address to add." buttons {"OK"}
else if contents of text field "serverTXT" of window "with" contains " " then
display dialog "There is a space in your Server/Share Address; please re-enter." buttons {"OK"}
else
set theRow to make new data row at the end of the data rows of serversDataSource
getServerInfo(window of theObject, theRow)
-- Clear out the server information
clearServerInfo(window of theObject)
end if
else if name of theObject is "removeBtn" then
set tableView to table view "servers" of scroll view "servers" of window of theObject
set selectedDataRows to selected data rows of tableView
if (count of selectedDataRows) > 0 then
tell window of theObject
-- Remove the server form the data source
delete (item 1 of selectedDataRows)
-- Clear out the server information
my clearServerInfo(window of theObject)
end tell
end if
else if name of theObject is "authenticateBtn" then
set panelWIndow to window "Authenticate"
display panel panelWIndow attached to window "with"
else if name of theObject is "connectBtn" then
tell window of theObject
set usernameVar to the contents of text field "usernameTXT"
set passwordVar to the contents of text field "passwordTXT"
set domainVar to the contents of text field "domainTXT"
--set keepProcessing to true
if usernameVar is equal to "" or passwordVar is equal to "" or domainVar is equal to "" then
display dialog "Please fill in the required credentials; either your username or password entry is blank." buttons {"OK"}
--set keepProcessing to false
else
set allRows to every data row of serversDataSource
repeat with curRow in allRows
set theServerShare to contents of data cell 1 of curRow as string
tell application "Finder"
activate
--Checks to see if the Volume is already mounted
-----------------------------------------------------------
set theShareVar to theServerShare
set dashLocationNumber to offset of "/" in theShareVar -- returns where the "/" is in currentServerShare as integer
set share_nameOnClientsDesktop to characters (dashLocationNumber + 1) thru end of theShareVar & ":" as string
if folder share_nameOnClientsDesktop exists then
--do nothing
else
try
mount volume "smb://" & domainVar & ";" & usernameVar & ":" & passwordVar & "@" & theServerShare
on error
display dialog "Your credentials are incorrect. Please enter your username & password again." buttons {"OK"}
--set keepProcessing to false
end try
end if
end tell
--if keepProcessing is false then
--exit repeat
--end if
end repeat
end if
end tell
else if name of theObject is "cancelAuthBtn" then
close panel (window of theObject)
else if name of theObject is "cancelMainBtn" then
quit
end if
end clicked
on selection changed theObject
if name of theObject is "servers" then
set theWindow to window of theObject
-- Set the server index to the current row, so that we can use it to update the right server later
set selectedDataRows to selected data rows of theObject
if (count of selectedDataRows) = 0 then
-- There wasn't any selected so clear the server information
my clearServerInfo(theWindow)
-- Disable the "Remove" buttons
set enabled of button "removeBtn" of theWindow to false
else
-- Enable the "Remove" buttons
set enabled of button "removeBtn" of theWindow to true
end if
end if
end selection changed
on will open theObject
-- Set up the contactDataSource so that the rest will be simpler
set serversDataSource to data source of table view "servers" of scroll view "servers" of theObject
-- Here we will add the data columns to the data source of the servers table view
tell serversDataSource
make new data column at the end of the data columns with properties {name:"Servers"}
end tell
end will open
(* ==== Server Handlers ==== *)
-- Empty all of the text fields
--
on clearServerInfo(theWindow)
tell theWindow
set contents of text field "serverTXT" to ""
set first responder to text field "serverTXT"
end tell
end clearServerInfo
-- Get the values from the text fields and set the cells in the the data row
--
on getServerInfo(theWindow, theRow)
tell theWindow
set contents of data cell "Servers" of theRow to contents of text field "serverTXT"
end tell
end getServerInfo