Hello there,
i played around with AppleScript in the late nineties and now try to remember it all and build upon it to puzzle together small homemade helpers. My current project is an app that will help me establishing project folders with their subsequent subfolders. I’d like to be able to choose the required subfolders from a list of checkboxes as well as setting certain presets wich are common for certain types of projects.
So i puzzled together a nice little interface in the IB and wrote some code. Here’s what i have so far: (the "display alert"s are just placeholders for the actions to build)
script rhpAppDelegate
property parent : class "NSObject"
on buttonClicked_(theButton)
set theSender to "" & {identifier of theButton}
if theSender is "alles" then
display alert "Alles auswählen"
else if theSender is "nichts" then
display alert "Nichts auswählen"
else if theSender is "printpreset" then
display alert "Preset für Print auswählen"
else if theSender is "webpreset" then
display alert "Preset für Web auswählen"
else
display alert "Anderer Button, nämlich " & theSender
end if
end buttonClicked_
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
What will i have to do to set say checkbox a, b and c to checked upon click of the sender with the identifier “webpreset”?
Sorry, i’m totally stuck and can’t seem to find advice.
regards
dieselross
You need to set up outlets for the checkboxes – properties set to missing value that you then connect to the checkboxes by click-draggibg in the .xib – and address those outlets.
First of all:
Thank you very much for your advice!
I have set the necessary properties like this.
script rhpAppDelegate
property parent : class "NSObject"
property kundendatenChecked : missing value
property rohdatenChecked : missing value
property schriftenChecked : missing value
property verworfenChecked : missing value
property korrekturenChecked : missing value
property druckdatenChecked : missing value
property abbildungenChecked : missing value
property cssChecked : missing value
property imagesChecked : missing value
property scriptsChecked : missing value
property webfontsChecked : missing value
on buttonClicked_(theButton)
set theSender to "" & {identifier of theButton}
if theSender is "alles" then
display alert "Alles auswählen"
else if theSender is "nichts" then
display alert "Nichts auswählen"
else if theSender is "printpreset" then
display alert "Preset für Print auswählen"
else if theSender is "webpreset" then
display alert "Preset für Web auswählen"
else
display alert "Anderer Button, nämlich " & theSender
end if
end buttonClicked_
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
And how do i then set the state to checked? Or what should the properties look like?
Thank you
dieselross
““
Edit: Just found and bought your book. Was looking for something like that.
You use the setState: method:
kundendatenChecked's setState_(0) -- or 1
Now i got this:
--
-- rhpAppDelegate.applescript
-- ProjectBuilder
--
-- Created by Holger Pleus on 15.08.13.
-- Copyright (c) 2013 Holger Pleus. All rights reserved.
--
script rhpAppDelegate
property parent : class "NSObject"
property projektname : missing value
property kundendatenChecked : missing value
property rohdatenChecked : missing value
property schriftenChecked : missing value
property verworfenChecked : missing value
property korrekturenChecked : missing value
property druckdatenChecked : missing value
property abbildungenChecked : missing value
property cssChecked : missing value
property imagesChecked : missing value
property scriptsChecked : missing value
property webfontsChecked : missing value
property auswahl : ""
on buttonClicked_(sender)
set theButton to "" & {identifier of sender}
if theButton is "alle" then
kundendatenChecked's setState_(1)
rohdatenChecked's setState_(1)
schriftenChecked's setState_(1)
verworfenChecked's setState_(1)
korrekturenChecked's setState_(1)
druckdatenChecked's setState_(1)
abbildungenChecked's setState_(1)
cssChecked's setState_(1)
imagesChecked's setState_(1)
scriptsChecked's setState_(1)
webfontsChecked's setState_(1)
else if theButton is "nichts" then
kundendatenChecked's setState_(0)
rohdatenChecked's setState_(0)
schriftenChecked's setState_(0)
verworfenChecked's setState_(0)
korrekturenChecked's setState_(0)
druckdatenChecked's setState_(0)
abbildungenChecked's setState_(0)
cssChecked's setState_(0)
imagesChecked's setState_(0)
scriptsChecked's setState_(0)
webfontsChecked's setState_(0)
else if theButton is "webprojekt" then
kundendatenChecked's setState_(1)
rohdatenChecked's setState_(1)
schriftenChecked's setState_(1)
verworfenChecked's setState_(1)
korrekturenChecked's setState_(0)
druckdatenChecked's setState_(0)
abbildungenChecked's setState_(0)
cssChecked's setState_(1)
imagesChecked's setState_(1)
scriptsChecked's setState_(1)
webfontsChecked's setState_(1)
else if theButton is "printprojekt" then
kundendatenChecked's setState_(1)
rohdatenChecked's setState_(1)
schriftenChecked's setState_(1)
verworfenChecked's setState_(1)
korrekturenChecked's setState_(1)
druckdatenChecked's setState_(1)
abbildungenChecked's setState_(1)
cssChecked's setState_(0)
imagesChecked's setState_(0)
scriptsChecked's setState_(0)
webfontsChecked's setState_(0)
else if theButton is "abbruch" then
kundendatenChecked's setState_(0)
rohdatenChecked's setState_(0)
schriftenChecked's setState_(0)
verworfenChecked's setState_(0)
korrekturenChecked's setState_(0)
druckdatenChecked's setState_(0)
abbildungenChecked's setState_(0)
cssChecked's setState_(0)
imagesChecked's setState_(0)
scriptsChecked's setState_(0)
webfontsChecked's setState_(0)
tell me to quit
else
set auswahl to ""
set theWorkingTitle to (stringValue() of projektname)
if kundendatenChecked's state() = 1 then set auswahl to auswahl & "Kundendaten" as list
if rohdatenChecked's state() = 1 then set auswahl to auswahl & "Rohdaten" as list
if schriftenChecked's state() = 1 then set auswahl to auswahl & "Schriften" as list
if verworfenChecked's state() = 1 then set auswahl to auswahl & "Verworfen" as list
if korrekturenChecked's state() = 1 then set auswahl to auswahl & "Korrekturen" as list
if druckdatenChecked's state() = 1 then set auswahl to auswahl & "Druckdaten" as list
if abbildungenChecked's state() = 1 then set auswahl to auswahl & "Abbildungen" as list
if cssChecked's state() = 1 then set auswahl to auswahl & "css" as list
if scriptsChecked's state() = 1 then set auswahl to auswahl & "scripts" as list
if imagesChecked's state() = 1 then set auswahl to auswahl & "images" as list
if webfontsChecked's state() = 1 then set auswahl to auswahl & "fonts" as list
-- make new folder at desktop with properties {name:theWorkingTitle}
-- repeat with ordner in auswahl
-- make new folder at folder theWorkingTitle of desktop with properties {name:ordner}
-- end repeat
set anzahl to count of items in auswahl
display alert "Anderer Button gedrückt, nämlich: " & theButton & return & return & auswahl & return & return & "Projektname: " & theWorkingTitle & return & return & "Die Anzahl der ausgewählten Ordner beträgt " & anzahl
end if
end buttonClicked_
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 “make new folder” part is commented out because it don’t work.
I don’t know what i have done wrong here.
Hi,
even in AppleScriptObjC Finder terminology like make new folder must be wrapped in a Finder tell block
Yeah! That did it! 
Thank you very much.