AppleScript in Xcode
I just got my mac about two weeks ago. I am a programmer, and i am trying to write some programs in applescript. I have encoutered two issues. First, I can not find any information or doumentation for the applescript language, such as a list of commands and ways to call variables, or even a tutorial that doesn't just say "applescript is very intuitive" like your just suposed to figure it out. Also, I have made a simple program that calls the shell script "defaults write com.apple.finder AppleShowAllFiles ON" to show hidden files like .DS_store files. I used an Xcode project to make a window with two buttons, ON and OFF, that use seperate script files ON.applescript and OFF.applescript in the project to turn the ability to see hidden files on or off when clicked. my problem is that, to make the change to see or hide hidden files come into effect, the finder must be restarted. But when I run my application, when a btton is clicked, it just does part of the programmed command, and turns the finder off, and then when clicked again, it continues and launches the finder again with the hidden files hidden or not, depending on which button is pressed. It is really frustrating, and is pushing me toward just giving up applescript and going back to C++.
MacBook Pro Mac OS X (10.4.9)
Here is the script of my Hidden Files app for the result on the on button being clicked:
on clicked theObject
tell application "Finder"
quit
end tell
do shell script "defaults write com.apple.finder AppleShowAllFiles ON"
tell application "Finder"
launch
end tell
end clicked
(This is pretty much all that is in this app in the way of scripts, the rest is done with the interface builder and .nib file)
After building this app, when I press the "HIDDEN FILES ON" button on my program, the finder shuts off... and thats all. There is no indication that it is loading, or doing anything else that migt prevent the finder from starting. Then, if I click the button again, then it turns the finder on, with all hidden files shown.I not sure how this is even possible, because my understanding of an executable is that it either runs, or returns an error message. And the "HIDDEN FILES OFF" button, with the same script exacly except for the ON in the 5th line replaced with OFF, works the same way, requiring 2 clicks on either button to fully complete the script's function.
MacBook Pro Mac OS X (10.4.9)
Similar Messages
-
Question regarding definition "Applescript in Xcode"
Hello, I've got a question:
How would you define Applescript in Xcode 3.1.2? Is one making an app with Cocoa? Is it called Applescript Studio or Cocoa Applescript?
Thanks in advancedAppleScript in XCode is generally known as AppleScriptObjC (AppleScript/Objective C). More details as Apple's Developer Site.
As a categorization, 'pure' AppleScript is generally perceived as a high-level scripting language (generally used on top of other processes that do the work. AppleScriptObjC is more of a high-level programming language since you can develop full-blown standalone applications. -
Applescript Studio/Xcode Tutorials
I'm a big applescripter, and just recently i learned about applescript studio in xcode. I downloaded xcode 3.2.6 and started having fun, but immediately found i was limited by obj-C (i know precious little). So i've been searching for a good bunch of applescript studio/xcode tutorials, but everything i find is for an older version of xcode! If any of you have seen anything for xcode 3.2.6, it would be greatly appreciated!
AppleScript Studio is the old framework, and is deprecated in Snow Leopard (you can still use it if you really want to, though). AppleScriptObjC is the new framework, and although you don't need to know Objective-C, it helps a bit to be able to read it, since most of the Cocoa documentation uses it (since ASOC calls Cocoa methods directly, Apple expects you to just use the existing documentation).
There is an AppleScriptObjC in Xcode tutorial at MacScripter, and Shane Stanley has an excellent e-book available at Mac OS X Automation that will get you up to speed fairly quickly - definitely worth the investment.
I also have a few example projects and references on my AppleScriptObjC web page that have been gathered from my various wanderings (there are also a couple of conversion examples from AS Studio and Obj-C). -
Applescript in Xcode Saving Preferences
Ok I am writing a simple applescript based xcode application but I can't figure out how to save these properties:
property fade_speed : true
property fade_on : false
property the_choice : false
property first_run : true
... between launches of the application which controls itunes. I want the user to be able to set preferences of if they want itunes to fade between songs every time they click the next or previous buttons or not to fade and to have a dialog pop up the first time they open the app and "the_choice" is their favorite playlist which they can play by clicking a button. How can I have these settings saved so that the user does not have to set them up each time?
Im using the latest version of Mac OS 10.5.7 and the latest version of Xcode.Properties do not persist between runs in AppleScript Studio like they do in a regular AppleScript. To save your preferences, etc., use the user defaults.
-
Hi,
I have a rather unusual project and don't know if I should use AppleScript or Xcode. I'm a bit used to applescript but don't know Xcode at all.
*Here is the main idea and goal :*
I have a mac mini which has a mediaplayer which runs video and such for digital signage.
That mac mini is connected to a USB Internet key (Roger's RocketStick). Everything works fine but I need to click on connect each time for it to connect on the internet and I must disconnect each night for the mac to shut down. Plus, I need to start the player and shut it off too. This is really a pain in the......
*Current setup* (+works okay but has alot of bugs that I can't put my finger on+)
I'm working with a script I did using automator and AppleScript, LogIn items for the startup script and iCal for shutdown times which then activates the shutdown script.
I thought I was pretty clever doing it this way, but sometimes for reasons unknown, the mac gets confused and loads both shutdown and startup scripts on bootup and hangs.
Guess on what type of code to use? Or do you have a better solution than what I'm doing.kpott wrote:
Anyway, the piece of software Roger's gave with their Internet USB key can't connect by itself, you must click on the connect button when their software boots or else it just finds the signal and waits for your command. I guess this was done intentionally by their part to save on bandwidth use.
You need to click a button. AppleScript can do this & is done all the time.
See the script below.
Get the scripting setup right then
Might be simple as:
keystroke return
The problem I'm getting is that I usually get the "Finder canceled "Shutdown"...." error message when the mac mini boots. "Shutdown" is the name of my script. This only happens sometimes, which is my biggest frustration. The method I'm using isn't stable.
Rename your script. The name is confusing. Something like myShutdown.
This is why I'm trying to look into a better way to work this out. I'm using Energy Saver to schedule the power on process and login items to start the script. The reason why I'm using iCal is to shutdown the computer using a script. I couldn't get the mac to start a script while Shutdown was initialized using the Energy Saver feature. PLUS, only to make things worst, on sundays, the mac must shutdown earlier in the day.
Interesting...
Remember you need to enable assistive devices.
This lets applications software access screen elements.
blue apple > system perferences > universal access > enable assistive devices
-- Write a message into the event log.
Run this program from the Script Editor. Click on the Event Log tab at the
bottom of the screen.
log " --- Starting on " & ((current date) as string) & " --- "
set the_item_ref to choose file with prompt "Select an html, text, or some other file Safari will display."
-- Activate
activate application "Safari"
-- Open the URL
tell application "Safari"
open the_item_ref
-- print
-- System Events interacts with the current active applications.
tell application "System Events"
tell process "Safari"
-- Your simulating typing on the keyboard. You need to allow time
-- for the application to run. It's always a guess about delay in seconds.
delay 3
-- Be sure your printer is up & running before printing.
keystroke "p" using command down
delay 3
keystroke return
delay 10
keystroke "w" using command down
end tell
end tell
end tell -- of Safari -
Need help with applescript and Xcode 4.3.2
I'm trying to write my first application that will involve a GUI. I can code applescript using script editor with a bit of effort, but I'm want to have users input more than one piece of information in the pop up. So, I download xcode, create my first applescript cocoa project go to MainMenu.xib and add a bunch of labels, text fields and buttons. Looks fairly nice... Go to start it and... nothing (well the window pops up, but it doesn't do anything). Unfortunately, I haven't figured out how to link the window to the applescript... So, how do I...
* Have the applescript prepopulate data in the text fields and pulldowns
* Once the user changes the data in the fields tell the applescript
* Tell the window to close and pass the control back to the applescript once either the cancel or submit button is pressed.
More detailed...
* What's an outlet and how do I use it here? Which of the 18 outlet(s) do i use for this?
* What's a property (referenced on one of the web pages I saw around applescript and cocoa) and do I need them here?
Looking at the documentation with xcode, there isn't a lot about xcode and applescipt. Looking at the web, the top links are a few years old. So, links to good relevent documentation would be very nice as well as direct answers to the questions
Thanks,
ScottI'm not sure why you are closing it, but the NSApplication class is what keeps track of the windows. If you don't want to connect the window to an outlet from the interface editor, you can use something like
set theWindow to current application's NSApplication's sharedApplication's mainWindow()
...and from there you can use whatever NSWindow methods, for example
theWindow's performClose_(me) -
AppleScript Studio/Xcode problem - Problem with text entries! Please help!
Hey, I've been up for hours each night looking for solutions to this but still have had no luck.
I am creating an app in Xcode/Applescript studio that will ask you to enter how many times you would like system events to repeat a certain keystroke. First of all, the code would look something like this:
on click theObject
If the name of theObject is equal to "myApplication" then
(Right here would be where the variables representing text in an input in the app's window would be, which I have absolutely no clue what to type.)
tell application "text edit"
activate
tell application "system events"
keystroke x (x representing a variable)
end tell
end tell
end clicked
and that's about as far as I can get. I want a variable representing the text in the main text entry box, but I have no clue how to access that text, or even know if it's submitted or detected when I hit a button. Hopefully you're following, as I am way to confused to fully explain it, but please try and help me out if you can.Hi Kamprath445,
Though this mentions iTunes, I think it has good examples you can use...
http://dougscripts.com/itunes/itinfo/keycodes.php
More in depth...
http://developer.apple.com/documentation/applescript/conceptual/applescriptlangg uide/conceptual/ASLR_variables.html -
Hello,
How do you change the text of a label (in a window) in Xcode, with AppleScript?
I use Xcode, but inside my app I use Xcode. Applescript studio actually, only it's isn't called like that anymore.
It's also called applescriptobjc...
Example:
I have a label, containing the text "Hello" in my main window.
Next to it, is a button. I want that button connected to an applescript action, like:
on thebuttonclicked_(aNotification)
set thelabel1 to "Bye!"
end thebuttonclicked_
Please help,
Isaiah v. Hunen
P.S. Is there a way to also use the text of the label, like;
on thebuttonclicked_(aNotification)
display dialog thelabel1
end thebuttonclicked_AppleScript Studio was deprecated in Snow Leopard - the new framework (AppleScriptObjC) is quite a bit different. One of the main differences is the way that user interface objects are referred to.
Typically, in your project you would create an outlet property for the label and connect that to the UI item. This outlet would then be used with the desired NSTextField methods (a label is just a text field that looks a little different).
property theLabel1 : missing value -- connect to the label text field
on thebuttonclicked_(aNotification)
theLabel1's setStringValue_("Bye!")
display dialog theLabel1's stringValue() as text
end thebuttonclicked_
Bindings can also be used to bind the value of the text field to a property. -
Applescript using XCODE 3.1.1 memory leak?
Does anyone know about a memory leak in applescript applications. I've written an application which displays images. It appears to retain each displayed image in memory untill it finally hangs. Does anybody know if this is new in 3.1.1 as I don't remember it happening with 3.0.0 ?
If anybody knows how to release it please let me know.
Thanks JS.Take a look at the discussion section and sample code below it in the docs for the "load image" command in the AppleScript Studio Terminology Reference. Loaded images are indeed retained, but supposedly can be deleted when you're done with them.
This doesn't appear to be new in Xcode 3.1.1 though.
Steve -
Use Applescript In Xcode To Make Timer In Window
Hi Everyone, I Making An Applescript and cocoa App In Xcode, and i need a Timer that is embedded in a interface builder window how do i do this?
One way would be to create a countdown handler using performSelector:withObject:afterDelay: to repeatedly count down, putting the current value into your text field. For example, using countdownText as your text field and countdownTime as the value to count down:
on countdown()
set countdownTime to countdownTime - 1
if countdownTime is less than 0 then -- clear timer and reset
parent's cancelPreviousPerformRequestsWithTarget_selector_object_(me, "countdown", missing value)
countdownText's setStringValue_("") -- clear the countdown text
-- reset countdownTime value and do whatever when countdown ends
else -- do it again
countdownText's setStringValue_(countdownTime) -- update the countdown text
performSelector_withObject_afterDelay_("countdown", missing value, 1.0)
end if
end countdown -
How to add applescript to xcode objc
Hello,
So I copied a applescriptobjc file from anther xcode project chosen from the menu. I pasted it next to the .h and .m file, but nothing of this applescript code works. Can somebody make a video on how to do it or tell me detailed and understandable how to do it?
ThanksWell, just throwing random files into an Xcode project isn't really the way to go, regardless of the language. AppleScriptObjC can be used in an Objective-C project, you just need to set things up to load the files and give Objective-C information about them so that they can be used:
The AppleScriptObjC framework needs to be added to your project;
An informal protocol needs to be set up to declare the handlers/methods in your scripts, since AppleScriptObjC doesn't have any headers;
You need to add statements to the main.m file to load the AppleScriptObjC scripts;
The script classes need to be instantiated in the Interface Builder or manually in your startup code.
I blew the dust off an older example project of mine that uses a couple of AppleScriptObjC files (they don't do much, mostly logs and a Finder window) from an Objective-C project - it can be downloaded here. -
Building a Universal Binary in Applescript Studio (Xcode 3.1)
Hello all,
I've been trying to configure Xcode 3.1 to build a UB of my applescript application, but I cant figure it out.
People tell me it doesn't even open on 10.4 or PPC macs (I have no way of testing it).
I've been going through the documentation for 2 days but I don't know what I'm missing for the life of me.
Can anyone help please?
Thanks in advance.See my answer in your other thread.
http://discussions.apple.com/thread.jspa?threadID=1844943&tstart=0
Eric -
Im use to program about twenty years ago in machine code and Basic but that was twenty years ago. I understand the concepts of programming and would like to get into it again but Im not really sure where to start. I could see the hobby expanding commercially maybe but for know Id like just to get back into it again. I cant think of a better machine to start with then the Mac. Would I have anything to gain by learning applescript, would I be better off learing C first, but what about Xcode. Is there anyone out there how could give me some advice so I can make a SWAG instead of a WAG at were to start?
Thanks
Sunt622I would second this from baltwo
I suggest going through the Xcode documentation, where you'll learn to make apps. AppleScript is an app management language. See it's guide. Once you get that sorted out, then peruse the developer forums.
I would add that you should get a book on Objective-C and one on Cocoa. -
Display dialog w/ applescript and xcode why so different
Hi all
Having an issue with a dialog box in xcode
In AS editor I have a long dialog box but xcode only shows half the message
display dialog "line 1
line 2
line 3
line 4
line 5
line 6
line 7"
For some reason applescript shows the whole message where as xcode only shows the first 2 lines and cuts off the rest.
Why is that?
How can I fix this?
I need to display no less then 7 lines in the dialogNever mind I figured it out
tell app "finder"
activate
tell app "system events" to display dialog "1
2
3
4
5
6
7
end tell
---- -
hello community,
i am writing a program in xcode with applescript.
the language itself causes no trouble to me, but
how can i write values to the info.plist or a plist i
created?
the purpose is, that i can log settings done in the
program itself.
thanks
DERandAre you talking about preferences, such as the User Defaults System? Most of the existing Cocoa documentation can be used for ASObjC, you just need to know how to convert the examples.
Maybe you are looking for
-
Creating certificate in ms-word for training and event management sap hr
hi, everybody, i used ole programming,to create certificate for attendee but i need to save in perticular directory,but all files are opening ,could anybody tell how to save in a perticular directory instead opening every file.
-
I can´t pair my Brookstone headphones with my Ipad 3
I can´t pair my Brookstone headphones with my Ipad 3, the Ipad simply doesn´t detect the device. I was using these headphones with my old Ipad 2. The device Manual of Instructions says it works with all Ipads. Any suggestions to solve the problem?
-
Hi, I need help with configuring CASUser Account for NAC AD SSO in a multidomain enviorment. We have two child domain (based on region) say A & B. We have created the casuser account in domain A. If a user from Domain A login, everything works fine a
-
Trouble importing video to iTunes and watching on ATV2
I have a ton of home video that I want to send from my mac to my new apple tv. I can't for the life of me get this video into itunes...and even when I can get itunes to import some of the clips, they don't show up in my library on the apple tv. I fig
-
Why has booting become slow?
Hi there. Whenever I turn on my macbook, it takes almost 10 minutes to reach the login page. This just started happening recently. Do you know what this can be attributed to and how I may fix it? Could it possibly be because of holding down the power