Hello all,
I am writing an app in Xcode with Applescript that would run a series of photoshop actions, and renaming functions and whatnot on images put into it. I already did the whole this as a standalone script, but I’m trying to beef it up with a full gui, which would allow me to make it much more dynamic.
I feel like I’m missing something right now. I have a table view set up that I can drop files into, and have it display their file names. Which is great. I had a lot of fun adding in neat little GUI elements like deleting from the database, deleting multiple files from the database, learning how to deselect files, etc. It was all cool, till I realized I had no idea how to link those database objects back with their parent files. I don’t even know where to start with this. I’ll post everything I have right now here, but it’s driving me crazy.
global theDataSource
global theTableView
property theImageFiles : {}
on awake from nib theObject
-- Create the data source for the table view
set theDataSource to make new data source at end of data sources with properties {name:"images"}
-- Create the "files" data column
make new data column at end of data columns of theDataSource with properties {name:"images"}
-- Assign the data source to the table view
set data source of theObject to theDataSource
-- Register for the "file names" drag types
tell theObject to register drag types {"file names"}
set theTableView to table view "images" of scroll view "images" of tab view item 1 of tab view 1 of window "main"
end awake from nib
on drop theObject drag info dragInfo
-- Get the list of data types on the pasteboard
set dataTypes to types of pasteboard of dragInfo
-- We are only interested in "file names" data types
if "file names" is in dataTypes then
-- Initialize the list of files to an empty list
set theImages to {}
-- We want the data as a list of file names, so set the preferred type to "file names"
set preferred type of pasteboard of dragInfo to "file names"
-- Get the list of files from the pasteboard
set theImages to contents of pasteboard of dragInfo
-- Make sure we have at least one item
if (count of theImages) > 0 then
--- Get the data source from the table view
set theDataSource to data source of theObject
-- Turn off the updating of the views
set update views of theDataSource to false
-- Delete all of the data rows in the data source
delete every data row of theDataSource
-- For every item in the list, make a new data row and set it's contents
repeat with theItem in theImages
set theDataRow to make new data row at end of data rows of theDataSource
set tid to AppleScript's text item delimiters
set AppleScript's text item delimiters to "/"
set theItem to last text item of theItem
set AppleScript's text item delimiters to tid
set contents of data cell "images" of theDataRow to theItem
end repeat
-- Turn back on the updating of the views
set update views of theDataSource to true
end if
end if
-- Set the preferred type back to the default
set preferred type of pasteboard of dragInfo to ""
return true
end drop
on clicked theObject
set lineCount to count every data row of theDataSource
display dialog ("there are " & (lineCount as text) & " items in this list.")
end clicked
on keyboard up theObject event theEvent
set keyPressed to (key code of theEvent)
if keyPressed is 51 then
set theSelectedRows to selected data rows of theTableView
if (count of theSelectedRows) > 0 then
if (count of theSelectedRows) is 1 then
display dialog "1 item will be removed from the list." & return & "Continue?"
set que to button returned of result
if que is "OK" then
set deleteQuery to 1
else
set deleteQuery to 0
end if
else
set theCount to (count of theSelectedRows)
display dialog ((theCount as text) & " items will be removed from the list." & return & "Continue?")
set que to button returned of result
if que is "OK" then
set deleteQuery to 1
else
set deleteQuery to 0
end if
end if
if deleteQuery is 1 then
set update views of theDataSource to false
repeat with i from 1 to (count of theSelectedRows)
delete (item i of theSelectedRows)
end repeat
call method "deselectAll:" of theTableView
set update views of theDataSource to true
end if
end if
end if
end keyboard up
As you can see, there are a lot of references to “file Names” but no references to the files themselves. I feel like it shouldn’t be a problem to grab the path at the same time that it’s grabbing the file name, and run a seperate database file in the background, so that when I delete a row from the file names database, I can delete it from the path database as well, but I can’t find documentation on anything even close to this.
Hope someone can help me before I go insane.