• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
another beginner's question
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

another beginner's question


  • Subject: another beginner's question
  • From: Marion Dickten <email@hidden>
  • Date: Thu, 11 Apr 2013 13:14:39 +0200

Hello,

I apologize for posting this kind of stuff but I haven't got anyone else I can ask.

I am currently working through Shane Stanley's book, and I am trying to put the cancel button into the app "Making progress" as is explained in chapter 13 of the book. I have wired up all the bindings and handlers correctly, but then I get an "unrecognized selector" error when I press the cancel button (it would be really helpful if the system told me *what* selector it doesn't recognize). The point is, for the life of me I cannot see how my code is any different from the code in chapter 13 of the book--- which works, of course. Can anybody see what I am missing? My code is:

script Making_ProgressAppDelegate
property parent : class "NSObject"


property theFilename : "App test file" -- bound property
property theFruit : "Orange" -- bound property
property theNumber : 10 -- bound property
property statusMessage : "App is idle" -- bound property
property theCounter : 0 -- bound property


property theWindow : missing value -- outlet connected to the window


property isIdle : true -- bound to enabled property of most elements

    

    property shouldStop: false


on doProcess_(sender)
try -- for testing
log "Begin" -- for testing


set my isIdle to false -- app is no longer idle
-- build file path and open file
set deskPath to path to desktop as text
set proposedPath to deskPath & theFilename & " (test only).txt"
try -- in case file was left open
tell current application to close access file proposedPath
end try
tell current application to set fileRef to (open for access file proposedPath with write permission)
set eof fileRef to 0
repeat with i from 1 to (theNumber as integer)
                log "0"
                handleEvents()
                if shouldStop is true then exit repeat
set my statusMessage to "Processing number " & i
set my theCounter to i
-- this where you would do your stuff
write (theFruit as text) & " number " & (i as text) & return to fileRef as text
tell theWindow to displayIfNeeded()
do shell script "sleep 0.25"
end repeat
-- close file and clean up
close access fileRef
set my theCounter to 0
            if shouldStop is true then
                set my statusMessage to "Cancelled after " & (i-1) & " times."
                set shouldStop to false
            else
                set my statusMessage to "Finished processing " & i & " times."
            end if
set my isIdle to true
log "End" -- for testing
-- for testing
         on error errMess
log errMess
end try
end doProcess_

    

    on handleEvents()
       repeat
           log "1"
           tell current application's NSApp to set theEvent to nextEventMatchingMask_untilDate_inMode_dequeue(((current application's NSLeftMouseDownMask) as integer), missing value, current application's NSEventTrackingRunLoopMode, true)
           log "2"
           if theEvent is missing value then
               exit repeat
            else
               tell current application's NSApp to sendEvent_(theEvent)
            end if
        end repeat
    end handleEvents

    

    on cancelPressed_(sender)
        set my shouldStop to true
    end cancelPressed_


on applicationWillFinishLaunching_(aNotification)
-- Insert code here to initialize your application before any files are opened 
end applicationWillFinishLaunching_


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


end script

The log gets as far as logging the "1" in the repeat in handleEvents(), then I get the error, and the app stops. I've checked the spelling again and again. Originally I had (((current application's NSLeftMouseDownMask) as integer) + ((current application's NSKeyDownMask) as integer) like it is in the book, and I got the same error.

Thank you,
Marion
 _______________________________________________
Do not post admin requests to the list. They will be ignored.
AppleScript-Users mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
Archives: http://lists.apple.com/archives/applescript-users

This email sent to email@hidden

  • Follow-Ups:
    • Re: another beginner's question
      • From: Shane Stanley <email@hidden>
    • Re: another beginner's question
      • From: Alex Zavatone <email@hidden>
  • Prev by Date: Applescript-ObjC: Actions and Outlets Tutorial?
  • Next by Date: Re: GIF to PDF with Applescript ONLY
  • Previous by thread: Re: Applescript-ObjC: Actions and Outlets Tutorial?
  • Next by thread: Re: another beginner's question
  • Index(es):
    • Date
    • Thread