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 dialog
Never 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
----
Similar Messages
-
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) -
Using the 'Display Dialog command with default answer "" returns two results; Button pressed and text.
I want to isolate the text to use in an application. Does anybody know the syntax to allow me to do this. until upgrade to Mavericks the text appears to have been the default return, now its the button.
ThanksFor those of you who may be experiencing the same problem I have manged to resolve the issue with the following lines:
Set mvar to (display dialog "add data" default answer "")
set mvar to text returned of mvar
This leave mvar with the text only to be used in an application etc, in my case numbers.
refer to page 161 of the Applescript Language Guide -
Applescript and Xcode Progress Bar
Hopefully someone here can give me a hand.
I have a very simple script that I would like to share with some of my coworkers who aren't so comfortable with the command line. So I would like to make a GUI with a progress bar using Interface Builder. I've searched high and low but can not find anything current that helps me. I think I might just be misunderstanding how outlets work and such, as I can get the script to run and the window shows, but the bar does not progress.
As a note, I'm using Xcode 4. Any help is greatly appreciated. Thanks in advance.A couple of things...
Your window and it's contents (including your progress indicator) normally do not redraw while you're within a handler. So chances are that the progress indicator is not getting redrawn until you exit the awakeFromNib handler... at which time your progress indicator has already been incremented to it's max value and so it would redraw as already full.
So, one option is to insert calls to tell your window to redraw after each update. But progress indicators have the ability to update themselves on a background thread. So, in this case, an easier option might be to tell your progress indicator to use threaded animation. So try inserting this at the top of your routine:
myProgressBar's setUsesThreadedAnimation_(true)
Another thing is that the "do shell script..." calls that you're doing are probably happening very quickly since all you're doing is a call to "mkdir". So even after adding the above line of code you may not see much if any difference in how quickly the progress indicator fills up.
You might try adding a small "sleep" to each do shell script call to slow things down a little. For example, for each of your shell script calls you could do something like this:
Change this:
do shell script "mkdir ~/Desktop/dir1"
To this:
do shell script "mkdir ~/Desktop/dir1 ; sleep 0.5"
That will add a half second delay to each shell script call and possibly allow you to see the progress indicator fill up more slowly.
Steve -
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.
-
Applescript and InDesign: Packaging/exporting -- can you help?
I found and tweaked a droplet script that isn't quite working right. I tried and failed to learn to do this myself. Any help is greatly appreciated! This is for InDesign CS6 -- you don't really need to know InDesign in order to help (at least I don't think so).
For the moment, I simply drag multiple InDesign files (for this example, "filename1.indd" and "filename2.indd") onto the droplet. InDesign packages them separately and outputs PDFs into each output folder. The problem is that it's creating too many folders and not putting things where I want.
Another thing: when InDesign packages a file, it creates a "Instructions.txt" file for each package that I need deleted. I'd really like this added to the script as well. Is it possible?
Current output (messy!)
Desired output (perfect!)
"exports" folder
"filename1" folder
filename1.pdf
"filename1" folder
filename1.indd
Instructions.txt
"filename2" folder
filename2.pdf
"filename2" folder
filename2.indd
Instructions.txt
baseFolder <--- directory of original files
"filename1" folder
filename1.indd
"PDF" folder
filename1.pdf
"filename2" folder
filename2.indd
"PDF" folder
filename2.pdf
Here's the script I have so far:
property baseFolder : (path to desktop as text) & "exports:"
on open mgItems
repeat with mgThisItem in mgItems
tell application id "com.adobe.InDesign"
try
open mgThisItem
set mgDocName to name of active document
set text item delimiters of AppleScript to ".indd"
set mgShortName to text item 1 of mgDocName
set targetFolderPath to my createFolder(mgShortName)
set text item delimiters of AppleScript to ""
set mgPackageFilePath to targetFolderPath & mgShortName as string
set mgProofFilePath to mgPackageFilePath & ".pdf" as string
set properties of PDF export preferences to properties of PDF export preset "[Smallest File Size]"
tell the active document to export format PDF type to mgProofFilePath without showing options
tell the active document to package to mgPackageFilePath with copying fonts, ignore preflight errors, copying profiles, updating graphics, including hidden layers,copying linked graphics and creating report
close active document saving no
on error e
display dialog e
end try
end tell
end repeat
display dialog "PDFs created and InDesign file packaged"
end open
on createFolder(nameString)
set macFolderPath to baseFolder & nameString
do shell script "mkdir -p " & quoted form of POSIX path of macFolderPath
return macFolderPath & ":"
end createFolder
Thanks very much!Easy enough. Note that I've moved things around a little to make a nicer flow:
on open mgItems
--make a date slug
set shortDateString to short date string of (current date)
set {oldTID, my text item delimiters} to {my text item delimiters, "/"}
set dateBits to (text items of shortDateString)
set my text item delimiters to ""
set datePrefixString to (text item 3 of dateBits & text items 1 thru 2 of dateBits & "_Release") as text
set my text item delimiters to oldTID
repeat with mgThisItem in mgItems
tell application "System Events"
--get path of the container of the passed in object
set targetFolderPath to path of container of disk item (mgThisItem as text)
end tell
tell application id "com.adobe.InDesign"
try
open mgThisItem
set mgDocName to name of active document
set text item delimiters of AppleScript to ".indd"
set mgShortName to text item 1 of mgDocName
-- set up folder and file references
set mgPackageFilePath to targetFolderPath & datePrefixString & ":" & mgShortName & ":"
set mgProofFilePath to mgPackageFilePath & "PDF:" & mgShortName & ".pdf" as string
set text item delimiters of AppleScript to ""
-- create dat folder, main folder and internal PDF folder; passing in POSIX path, though most everything ele uses HFS paths
my createFolders(POSIX path of file (mgPackageFilePath & "PDF:"))
set properties of PDF export preferences to properties of PDF export preset "[Smallest File Size]"
tell the active document to export format PDF type to mgProofFilePath without showing options
tell the active document to package to mgPackageFilePath with copying fonts, ignore preflight errors, copying profiles, updating graphics, including hidden layers, copying linked graphics and creating report
close active document saving no
on error e
display dialog e
end try
end tell
-- delete the instructions file
tell application "System Events"
delete file (mgPackageFilePath & "instructions.txt")
end tell
end repeat
display dialog "PDFs created and InDesign file packaged"
end open
on createFolders(pathString)
do shell script "mkdir -p " & quoted form of pathString
end createFolders -
AS Droplet in XCode - Problem with display dialog with title
hi,
i am using XCode to create an AS droplet.
wondering why i cant set a title to my display dialog code.
during search in this forum i found this thread:
http://discussions.apple.com/thread.jspa?messageID=6364939�
but to be honest, i didn't expect that i am limited in Xcode too.
Short code example:
display dialog "foo"
works
but
this code:
display dialog "foo" with title "bar"
not.
Would be great to find a workaround to get dialogs with titles.
And on the other hand to understand why i cant use title in Xcode.
btw: is it possible to format the output of a display dialog ?
i.e. creating new lines ?
best regards
fidelHello
I'm not sure but you may try 'run script' to invoke 'display dialog' of Standard Additions.
Something like this.
--SNIPPET
set t to "line 1
line 2
line 3
line 4"
run script "display dialog \"" & t & "\" ¬
with title \"Testing\" ¬
buttons {\"OK\"} default button 1"
--END OF SNIPPET
As for 'display dialog' in AS Studio, it differs from and overrides 'display dialog' command in Standard Additions. Don't know why it does not have 'with title' which is rather new parameter introduced with AS 1.10 (OSX 10.4).
cf.
AppleScript Studio Terminology Reference (pdf)
Panel Suite > Terminology > Commands > display dialog
Regards,
H
Message was edited by: Hiroto -
Applescript: display dialog while doing shell script
Hello there,
I'm making an applescript app for my company, and had a question.
The functionallity of the app is working great, but there is a certain step which can take up to several minutes.
This can give the user the feeling that nothing is happening and things are stuck.
Is there a possibility to display a dialog as long as the action (shell script) is running?
Something along the lines of "Now performing action X. please wait...)
Thanks for your thoughts!
GrtzWith regular AppleScript you can start the shell script in the background (see do shell script in AppleScript) and then put up a dialog, although you would have to periodically check to see if the shell script is finished. In Lion, the AppleScript Editor has a Cocoa-AppleScript template that you can use (kind of a wrapper application that lets you use various Cocoa methods without having to use Xcode), in which case you could put up an indeterminite progress indicator and then do the shell script.
AppleScript Studio is deprecated as of Snow Leopard, but there are some AppleScriptObjC in Xcode tutorials at MacScripter. An additional source of information and templates is macosxautomation, but they seem to be having some server problems at this time. I also have a Progress Window template application example, it can be downloaded here. -
Applescript: display dialog until memory card is inserted
I'm developing an applet to automate the process of copying video footage from my camera's memory cards onto my hard drive. It works perfectly, except that I cannot quit it. Here is the part of the code that needs help. It checks every 5 seconds for a memory card and, if one is inserted, continues to copy everything off it.
repeat
set cardIn to 1
with timeout of 86400 seconds
tell application "Finder"
repeat while cardIn is 1
if exists disk "EOS_DIGITAL" then
set cardIn to 0
else
delay 5
end if
end repeat
end tell
end timeout
(the rest of the code)
end repeat
The problem is that there is no way I can find to quit once it is in this wait loop. The menu command to quit and the Command-Q hotkey both do nothing so I have to force quit when done. What I'd like is to be able to have a dialog displayed asking this user if they want to quit while it's waiting, but I don't know how to do that without it having to "give up after 5 seconds". That makes a new dialog display again every 5 seconds when it rechecks for memory cards, which would get very annoying for anyone using the computer.
I wish something like this would work...
repeat until (list disks) contains "EOS_DIGITAL"
display dialog "Waiting for card..." buttons {"Quit"}
tell me to quit
end repeat
...but it still waits for a button to be clicked in the dialog. I want this to be a truly automatic process, where plugging in a memory card triggers the whole copy process (which is already done and works perfectly) so I would rather not have to click a button to continue.
Is there any way to have a dialog displayes with a quit button that automatically goes away once a memory card is inserted without using "giving up after x seconds"?Keeping a script or application locked up inside delays or repeat loops will keep it from responding to system events. There are a few ways to monitor when a volume gets mounted:
Write your application using AppleScript in Xcode to watch for a workspace notification;
Use launchd or a folder action to watch the /Volumes folder (an alias is added to the folder when a volume is mounted);
Make your script into a stay-open application and use an idle handler to periodically check. -
Applescript buttons returned from display dialog
Hi!
I have been learning Applescript for about a month and found the following issue which I thought was an easy implementation.
On the "text returned" I get the error condition described. Do not understand!
Any help would be appreciated.
display dialog ("ENTER COMPANY NAME") with title ("TOTAL SHARE SPECIFICATION")
buttons {"Cancel", "Company"} default button "Company" default answer ""
set BUTTON_Returned to button returned of the result
set CompanyName to text returned of the result
error "Can’t get text returned of \"Company\"." number -1728 from text returned of "Company"
MacBook 6.1 OS X Yosemite Vn 10.10.1
Script Editor Vn. 2.7 (176)
Applescript 2.4
RegardsNo question that Applescript can be frustrating to learn. Many things about it have to be figured out by trial and error and when dealing with scripting applications all bets are off. The application designer can pretty much do as they want so what works in one app might not work in another even though you are using the same and correct applescript
I find Introduction to AppleScript Language Guide by Apple to be a good source of answers and usually always have it open when I'm scripting for quick reference.
Spend some time getting familiar with the script editor. It is intelligent and can usually steer you in the right direction when it comes to debugging. Especially get use to and pay attention to the colors it assigns to items in your script.
For example in your original script notice the colors of Button_Returned and CompanyName (your variables) and compare those to result and button returned. Also notice how text returned is a different color from button returned even though both are essentially the same thing. This is an indication that something is not right and it is where the error message occurred. (for a list of the default colors used open the Script Editors preferences and look at the Formatting tab).
Notice also how the editor formats your scripts, again the way the script gets formatted can tell you a lot if there is an error.
Finally the error messages while cryptic can offer some clues. In your case the error message was
error "Can’t get text returned of \"Company\"." number -1728 from text returned of "Company"
generated by the line
set CompanyName to text returned of the result
The last part of the error message is essentially the line that caused the error after evaluation. So here result evaluated to “Company” which doesn't seem right, display dialog returns a record.
Finally there is the log statement which will print its value to the log window
Hope this helps
regards -
Applescript Display Dialog Default Answer Rendering Issue
After I installed Lion, I started having issues with Applescript rendering a dialog with a textbox.
This is the sort of thing I end up seeing:
The text box in the dialog doesn't render properly, and it's not possible to enter anything into it. I've played with the display dialog parameters but it doesn't matter if I give an empty string for the default answer or other text, the behaviour is always the same.
Does anyone have any ideas as to what the issue might be? I suspect I might need to reinstall Lion, but I'm not sure that's even going to clear up the issue.
Thanks in advance.Tried replacing 'Standard Additions' osax, dumping editor prefs, dumping ALL user prefs (not recommended for faint of heart), using a different copy of Script Editor. Nothing helped.
The user account displaying the bug is an old one; likely updated continuosly from the days of Tiger or earlier.
A std account on the same drive, which merely went through the Snow Leopard -> Lion transition, does not exhibit the edit-text display bug.
So I bit the bullet, and used Migration Assistant to move to a new account on a clean install of Lion on a spare hard drive. 3.5 hours later, the Applescript edit text display bug is gone.
As far as I can tell, all docs, Apps etc. made it through intact.
If that continues to look true over the next few days, I'll try using SuperDuper! to copy the new drive back to the older, faster HD.
Perhaps some other Lion bugs'll also go away now that I've got a cleaner install. -
Applescript & Automator- display dialog title
I'm trying to make an Automator service. For one of the steps I would like to use an Applescript that looks something like the one below.
set dpaste to "Enter a title, press tab, add some text, and click Continue when you're done."
set dialog_title to "Post To Blog"
set dpastedialog to display dialog dpaste with title dialog_title with icon 1 buttons {"Cancel", "Continue"} default button 2
if button returned of dpastedialog is "Continue" then
tell application "System Events"
activate
keystroke "v" using command down
end tell
end if
However, the line "set dpastedialog to display dialog dpaste with title dialog_title" seems to be giving Automator some trouble. Whenever I try to compile/run the script, I get the following error message from Automator: "Expected end of line, etc. but found identifier" with the variable "dialog_title" selected.
When I run this script from Applescript Editor I get no trouble.
Thanks!Test the script in the AppleScript Editor until you resolve the issue. Alternatively, post to the AppleScript forum under OS X Technologies.
-
AppleScript Newbie - Display dialog box when quitting an application
Hello.
I was wondering if it's possible to write a script that displays a dialog box (in this case one saying "BACK UP!!!!") everytime i quit Final Draft.
Thanks.
F.A regular AppleScript does not have the ability to get system notifications, so you would have to do something like have the script continually check (poll) for applications that are running. A Cocoa-AppleScript does have the ability to do Cocoa-y stuff such as register for system notifications, so you can create a new applet (AppleScript Editor > File > New from Template > Cocoa-AppleScript Applet), paste in the following, and save it as an application (uncheck the option to show the startup screen):
property theApps : {"Final Draft"} -- a list of applications to watch for
on run -- example
# add observers for workspace notifications
tell current application's NSWorkspace's sharedWorkspace's notificationCenter
addObserver_selector_name_object_(me, "appQuit:", current application's NSWorkspaceDidTerminateApplicationNotification, missing value)
end tell
-- tell application "Final Draft" to activate
end run
on appQuit_(aNotification) -- an application quit
# aNotification's userInfo record contains an NSRunningApplication instance that we can get properties from
set theApplication to (aNotification's userInfo's NSWorkspaceApplicationKey's localizedName()) as text
if theApplication is in theApps then
tell current application -- me
beep 3
activate -- make sure dialog comes to front
display dialog "BACK UP!!!!" with title "Final Draft quit notice" buttons {"OK"} default button 1
quit
end tell
end if
end appQuit_
When the application is run it will sit there and receive notifications when other applications quit, and checks to see if it was the application you want. -
Display dialog, getting both text returned and button returned
I am most of the way through my first major project in applescript. I want to get both the text returned of and the button returned of a dialog box. Is this possible?
So basically i want to do the below without having the dialog box run twice.
set thebutton to the button returned of (display dialog "Already Assigned!" & return & "Please assign a new letter" default answer "…" buttons {"Cancel", "Delete Previous Location for this Letter", "OK"} default button "OK")
set theLetter to the text returned of (display dialog "Already Assigned!" & return & "Please assign a new letter" default answer "…" buttons {"Cancel", "Delete Previous Location for this Letter", "OK"} default button "OK")
RichWell thanks for the fast response, both work fine, cheers. That problem is now sorted.
However while i was waiting for the responses i came across another problem, i would like to delete a specified item from a list. This is not the actual script but i was using it to test the syntax. So basically how would i go about deleting the the letter P from a list PQ
set letterlist to {}
display dialog letterlist as string
set namep to "P"
copy (namep) to end of letterlist
set nameq to "Q"
copy (nameq) to end of letterlist
display dialog letterlist as string
set theKeyPressed to "P"
repeat with each_item in letterlist
if each_item contains theKeyPressed then
delete each_item
end if
end repeat
display dialog letterlist as string
Rich -
Applescript: display dialog / saving to . . .
The following script always has the document folder selected in the "save as" window
How do I designate another locaiton such as the desktop
or even create a folderat the desk top and have it selected as the save to
(G5 PPC OS X 10.5.8 Applescript)
Thank you
say (text returned of (display dialog ¬
"Enter what you would like synthesized into a file." default answer ¬
"Welcome to Mac OS X.")) saving to (choose file name with prompt ¬
"Choose where you would like to to save the file." default name "say.aiff")The choose file / defaul location is a reference to a folder which is useful
But how do I change the locaiton from the documents folder to the desktop
The desktop is not a folder and won't work with this comand
I googled and come up with a solution:
say (text returned of (display dialog ¬
"Enter what you would like synthesized into a file." default answer ¬
"Welcome to Mac OS X.")) saving to (choose file name with prompt ¬
"Choose where you would like to to save the file." default name "say.aiff" default location path to desktop)
Thanks for pointing me in the right direction
Maybe you are looking for
-
"It is formatted incorrectly, or is not a format that iBooks can open". Can anyone help me with this message of a book that I purchased on iBooks, read, highlighted in the book and now I can't open it anymore. Please help!!!
-
What's the best practices for mirroring a (symetric) vector design?
ok, say I'm making a detailed user icon (persons head and shoulders) for some icons, etc that need to scale from icons to general graphics for web and print. I can create the silhouette easily by tracing around my pencil sketch or making it up on the
-
Load Balance guest Internet access via two different DMZ zones at two sites
Hi Sir, My customer has the following unified wireless guest access requirement: - There are 2 internet links and dmz zones at two different locations, Site A and Site B - Data centre is at Site A - WiSM is proposed to be installed at the Cat 6500 in
-
Remove RSS subscribe button from Iweb 08
How do I remove the RSS feed button from some of my pages/photo galleries in iWeb 08? I also noticed that my navigation bar does not show up in Dreamweaver CS3. The navigation bar would show up fine in the old iWeb. Is there a compatibility issue wit
-
Connecting a Dell 1100 laser printer to iMacs
I have a two iMacs (one is brand new and one is 4 years old) and want to connect a Dell 1100 laser printer to them. Is this possible to do and if yes what software do I need (and where can I get it)? Thanks!