Adding files to list / including files in build

Hi, I’m working on a program that will take files and process each one using two user inputs, an IP address and a password. More specifically, it is for sideloading .bar files to a blackberry playbook.

I had created an apple script but I wanted to simplify the process by creating a UI, that’s where AppleScriptObjC comes in. I found this site, but I cant figure out how to add the files to be processed. I used a simple table to hold the files, but I don’t yet know how to code it.

The program uses a .jar file to connect to the playbook and load the files, so I’d also need to direct the application to the the directory where the terminal command will be run. Can anyone help me with this? My code is included below:

--
--  oBarLoadAppDelegate.applescript
--  oBarLoad
--
--  Created by Mikel Calderon on 2/12/12.
--  Copyright (c) 2012 NeuronApps. All rights reserved.
--
property NSMutableArray: class "NSMutableArray"

script AppDelegate
	
    property parent : class "NSObject"
    
--IB_Outlets
--Developer Mode Settings
    
    property textField : missing value
    property secureTextField : missing value
    
--BarFiles to load

    property theDataSource : {}

--IB_Bindings
    
    property pbDevIp : ""
    property pbDevPass : ""
    property pbToolsPath : ""
    
--Begin Actions
    
	on applicationWillFinishLaunching_(aNotification)
    end applicationWillFinishLaunching_

--Record user IP and Password to use when processing files
    
    on updateDeveloperSettings_(sender)
        set pbDevIp to (textField's stringValue()) as string
        set pbDevPass to (secureTextField's stringValue()) as string
    end updateDeveloperSettings_

--Add .bar files to table list
    on addFile_(sender)
       
    end addFile_
    
    on loadBar_(sender)
        if pbDevIp as boolean is 0 then
            display dialog "Required developer IP is missing" with title "oBarLoad Warning"
            
        else if pbDevPass as boolean is 0 then
            display dialog "Required password is missing" with title "oBarLoad Warning"
        
        else if addFile as boolean is 0 then
            display dialog "Please select a .Bar file!"
        else 
            display dialog " Attempting .Bar Load" 
            
        end if
    
    end loadBar_
  
--This is the part where I'm stuck, every time i build the application I get an error 

    (* set filecount to 0
    on ButtonClicked_(sender)
            (repeat with i in loadBar_
                set filecount to 1
                tell application "Terminal"
                    set currentTab to do script "cd /Users/username/location/Playbook_Tools" -- replace what is inside the quotes with the directory where BarDeploy.jar is saved within the bundle

--To set path to bundle contents
 --current application's NSBundle's mainBundle()'s bundlePath()'s stringByAppendingPathComponent_("Contents")
                    set filename to POSIX path of i
                    do script "java -Xmx512M -jar \"BarDeploy.jar\" -installApp -device " & pbDevIp & " -password" & pbDevPass & " " & filename in currentTab 
                    do script "exit" in currentTab
                    delay 10
                end tell
            end repeat)
    end ButtonClicked_
        if filecount < 1 then
            tell application "Terminal"
                do script "exit"
            end tell
        end if *)
    

	on applicationShouldTerminate_(sender)
		-- Insert code here to do any housekeeping before your application quits 
		return current application's NSTerminateNow
	end applicationShouldTerminate_
end script

If it helps, this is what I want the final product to look like. I’d also like to add a drop on top of the Developer Settings box, but don’t know how to do that either. Please help

Uploaded with ImageShack.us

The first obvious thing to stick out is that you have a handler called loadBar_, then a little later you say “repeat with i in loadBar_”. Something doesn’t add up…

I’m new to scripting/coding so please let me know how to set this up correctly. I have seen some applications here with a repeat function, but I haven’t found documentation on how to implement it. Thanks!

The repeat function is basic AppleScript, and without the basics of AppleScript I’m afraid you’re in for a rough ride.

It looks a bit like you’re trying to run before learning to walk. You should start by learning AppleScript itself – you can download the AppleScript Language Guide as a good starting point. Then get your basic code working without a UI. Adding the UI should come last.

I hope that doesn’t sound negative, but without the basics you’re just going to face frustration after frustration.

I appreciate your help. I did get this script to work initially without a ui and I thought it would be a simple process to plug it in to a UI. so much for wishful thinking.

in case you want to see the original script without xcode:

property passwd : ""
property pbip : ""

set ipd to ""
set pass to ""

set pass to display dialog "Enter your debug password" default answer pass
set passwd to text returned of pass
set ipd to display dialog "Enter your playbook IP" default answer ipd
set pbip to text returned of ipd
display dialog passwd & " " & pbip

set filecount to 0
on open loadbar
repeat with i in loadbar
set filecount to 1
tell application "Terminal"
set currentTab to do script "cd /Users/username/location/Playbook_Tools" -- replace what is inside the quotes with the directory where you have Playbook Tools
set filename to POSIX path of i
-- do script "java -Xmx512M -jar \"BarDeploy.jar\" -installApp -device 127.0.0.1 -password passwordhere " & filename in currentTab -- change 127.0.0.1 to your actual developer ip found in the status bar of your pb, also change passwordhere to your actual password
do script "java -Xmx512M -jar \"BarDeploy.jar\" -installApp -device " & pbip & " -password" & passwd & " " & filename in currentTab -- change 127.0.0.1 to your actual developer ip found in the status bar of your pb, also change passwordhere to your actual password
do script "exit" in currentTab
delay 10
end tell
end repeat
end open

if filecount < 1 then
tell application "Terminal"
do script "exit"
end tell 

Ok so its back to the drawing board… :frowning:

The first thing you should look at is whether you can use “do shell script” rather than scripting Terminal.

When you move to ASObjC, you don’t need it in a repeat loop. But you need to think where you will get the file list from, to populate your table. That would be a good starting point.

On second thought, I think for my purposes It would be best to leave the table out of the picture and just create a droplet to get the files.

Thanks for the tip on do scripts, I guess you learn something new every day. I followed your advice and downloaded the Apple script guide, as well as your book. I’ll be reworking my app in the weeks (if not months) coming. I’ll post back to ask for more help as needed

Good luck!