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
Similar Messages
-
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: 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 Display dialog if clause
What I'm trying to do now is have a pop up trigger from a calendar event(already know that part) and ask a user if they are ready to launch another workflow. If they select NO I want there to be a 5 minute delay and then have the same question asked again. I cant figure out how to loop the original question back through and I know there has to be a way to do it.
Heres my code so far...
set question to display dialog "If you're ready to clock in, punch for lunch, or clock out click YES. If you are stuck on a chat cancel this bad boy." buttons {"No", "Yes"} default button 2
set answer to button returned of question
if answer is equal to "Yes" then
tell application "Finder" to activate
tell application "System Events"
keystroke "c" using {command down, control down, option down}
end tell
end if
if answer is equal to "No" then
display dialog "Automator will snooze for 5 minutes" buttons {"Snooze", "Snooze"} default button 2
delay 300
display dialog question
end if
Thanks in advanced for any input!You can also just put the whole thing in another repeat statement:
repeat -- forever
set answer to button returned of (display dialog "If you're ready to clock in, punch for lunch, or clock out click YES. If you are stuck on a chat cancel this bad boy." buttons {"No", "Yes"} default button 2)
if answer is equal to "Yes" then
tell application "Finder" to activate
tell application "System Events"
keystroke "c" using {command down, control down, option down}
end tell
exit repeat
else
display dialog "Automator will snooze for 5 minutes" buttons {"Snooze"} default button 1 giving up after 10
delay 300
end if
end repeat -
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 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 & 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. -
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 -
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
---- -
How can a remotely launched Applecsript display dialog?
I have many Mac-computers running a variety of Mac OS X systems, including Tiger, Leopard, and Snow Leopard. On Tiger and Leopard, a Terminal bash-script could launch a compiled and saved Applescript (in /Applications/myLogout.app), which uses "say" to tell the user the system is going down in two-minutes. It then waits (delay 120), and then uses "say" again with this message, "System going down in 10 seconds". That's followed by a "display dialog" with the same message. The User could "Cancel" to stop the execution of the Applescript. If not, the applicaton proceeds to do cleanup work, like eliminating pesky /var/tmp files that invariablely end up as "Recovered" files or folders, and then it does "shut down".
I could remote login from another computer and execute this simple bash-script:
#!/bin/bash
if [ -x "/Applications/myLogout.app" ] ; then
osascript /Applications/myLogout.app display >/dev/null 2>&1"
else
echo "Can't find Logout application"
fi
exit 0
This bash-script would wait at the osascript command until the Applescript terminated, which it did either because someone clicked Cancel in the dialog, or the "shut down" command occurred. My session then regained control, and usually was quickly terminated as a remote session.
But now, Snow Leopard wouldn't properly execute the Applescript. It always fails for lack of a WindowServer connection to my remote session.
I can't use launchd for this because of similar restrictions. For one thing, I have no clue who might be the active user on the target computer, and never had to worry about that because the "display dialog" was always presented to the "current" user. So, basically, Apple has removed the capability that existed in both Tiger and Leopard. Furthermore, their "solution" of using launchd doesn't cover this scenerio: - - remote launch of a UI application that warns the "current user", does a lot of cleanup work, and shuts down the computer.
I can do everything in a bash shell except present a dialog to give the "current user" a chance to Cancel. Basically, the myLogout application can be launched by the "current user", and since it doesn't have an input parameter, it doesn't wait or do the dialog. That works. But even when called from a bash-script WITHOUT a parameter (that's the "display" word in the sample), it still fails in Snow Leopard.
One final note: The "Product" listed with this post is NOT my Snow Leopard system, but it's NOT 10.4.11 either. I'm on 10.5.8One of us is confused about something, and I'm not sure which of us it is.
What message are you trying to pass? If you want a formulaic "Shutdown in two minutes" message then code it directly into the script and don't bother with passing it. If you want a custom message that might change on different runs, then the easiest solution is to call a handler of the application on the remote machine and pass the message as a parameter. just for an example, do this:
Put this script as a stay-open script application on the remote machine:
global idleInterval, message
on idle
try
-- error catching. when you call handler x(), first the script's run handler will run, then the idle handler, then x(), and the the idle handler in a loop. this prevents unset variable errors on the first pass.
message
idleInterval
on error errstr
return 1
end try
if idleInterval is "Start" then
say message
set idleInterval to 10
else if idleInterval is 10 then
say message
set idleInterval to 5
else
display dialog "System wants to shut down"
set idleInterval to 1
quit
end if
return idleInterval
end idle
on x(textMessage)
set idleInterval to "Start"
set message to textMessage
end x
go back to the admin machine and run this command in the applescript editor:
tell application "ShowMsg" of machine remoteMachine
x("Whoohoo!")
end tell
If it asks for authorization, give it. You can either save it in your keychain or we can work through the auth problem next. -
Display dialog ... giving after integer
After updating to Mountain Lion I experienced some problems with the AppleScript scripts I use in a Filemaker Pro environment.
This necessitated me to change from QTP to QTP 7.
The following script reflects the FMP environment; when I try to abstract from the FMP environment, I encounter other problems.
tell application "QuickTime Player 7" to launch
tell application "FileMaker Pro"
activate
set url_path to cell "bestandspad" of current record
end tell
set tekst to ""
tell application "QuickTime Player 7" to getURL url_path
delay 0.1
tell application "System Events"
set visible of process "QuickTime Player 7" to false
repeat until visible of process "QuickTime Player 7" is false
end repeat
end tell
tell application "QuickTime Player 7" to set doc1Exists to (exists document 1)
if not doc1Exists then
set tekst to "next"
else
tell application "QuickTime Player 7" to play document 1
end if
set the clipboard to tekst
set tekst to ""
repeat
display dialog "Interrupt" buttons {"Stop", "Pauze"} giving up after (my secLeft())
set {b, fin} to {button returned, gave up} of result
if fin then exit repeat
if b = "Stop" then
set tekst to "Stop"
exit repeat
else
tell application "QuickTime Player 7" to pause document 1
display dialog "Verder gaan ?" with title "" buttons {"Stop", "Hervat"} default button 2
set b to button returned of result
if b = "Hervat" then
tell application "QuickTime Player 7"
tell document 1
if duration = current time then exit repeat
play
end tell
end tell
else
set tekst to "Stop"
exit repeat
end if
end if
end repeat
set the clipboard to tekst
on secLeft()
tell application "QuickTime Player 7"
tell document 1
set d to (duration - current time)
end tell
end tell
set d to round d rounding up
if d < 1 then set d to 1
return d
end secLeft
tell application "QuickTime Player 7" to close document 1 saving no
tell application "QuickTime Player 7" to quit
Everything works fine, but.
The problem is with the 'display dialog ... giving up after (my secLeft())'
This is supposed to return fin=true when current time equals duration or when my secLeft=0; it always returns fin=false
This program runs fine on the AppleScript editor; 'current time' sometimes poses a problem in other programs.
Any idea how to correct 'dispaly dialog (without moving back to QTP)?To induce you to a response I submit the program in a simplified form, so that you can run it in the AppleScript editor after copying; you only have to fill in the url_path.
tell application "QuickTime Player 7" to launch
set url_path to "/Users/your name/Desktop/song title.mp3"
set tekst to ""
tell application "QuickTime Player 7" to open url_path
tell application "QuickTime Player 7" to set doc1Exists to (exists document 1)
if not doc1Exists then
set tekst to "next"
else
tell application "QuickTime Player 7" to play document 1
end if
set the clipboard to tekst
set tekst to ""
repeat
display dialog "Interrupt" buttons {"Stop", "Pause"} giving up after my secLeft()
set {b, fin} to {button returned, gave up} of result
if fin then exit repeat
if b = "Stop" then
set tekst to "Stop"
exit repeat
else
tell application "QuickTime Player 7" to pause document 1
display dialog "Continue ?" with title "" buttons {"Stop", "Resume"} default button 2
set b to button returned of result
if b = "Resume" then
tell application "QuickTime Player 7"
tell document 1
if duration = current time then exit repeat
play
end tell
end tell
else
set tekst to "Stop"
exit repeat
end if
end if
end repeat
set the clipboard to tekst
on secLeft()
tell application "QuickTime Player 7"
tell document 1
set d to (duration - current time)
end tell
end tell
set d to round d rounding up
--if d < 1 then set d to 1
return d
end secLeft
tell application "QuickTime Player 7" to close document 1 saving no
tell application "QuickTime Player 7" to quit
It seems, that 'repeat' is not working. The value of secLeft() is not refreshed while playing.
I tried repeat while and repeat until, but to no avail.
Comment please. -
How do I use Display Dialog to get back a date?
Can anyone tell me how to use Display Dialog to get back a date?
I am using the following code that does not work. It does not accept anything. And I have searched high and low for an answer to my question and found nothing.
repeat
display dialog "When should I remind you (date)?" default answer ""
try
if the text returned of the result is not "" then
set the requested_text to the date returned of the result as date
exit repeat
end if
on error
beep
end try
endrepeat
display dialog requested_text
The code is based on what I found in AppleScript 1-2-3 (page 300). It shows examples for getting text and numbers but not one for dates.
For what it is worth, my goal is to create a script that will convert an email from Evernote into an iCal Reminder. To do so, I want to ask the user (myself) for the reminder's date and time. I am assuming I need to ask for each separately. I also assume that once I get the date and time for the reminder, it should be relatively straightforward to 'make' a 'todo' with an alarm.
Thanks in advance.
-DavidHi David,
Try this:
repeat
set theCurrentDate to current date
display dialog "When should I remind you (date)?" default answer (date string of theCurrentDate & space & time string of theCurrentDate)
set theText to text returned of result
try
if theText is not "" then
set theDate to date theText -- a date object
exit repeat
end if
on error
beep
end try
end repeat
display dialog (date string of theDate & space & time string of theDate)
You might also have a look at this page of the AppleScript Language Guide.
Message was edited by: Pierre L. -
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 -
Make applescript display terminal prompts
Hi,
I new to applescript, and am trying to to automate some terminal commands. At one point, the user is required to enter information to complete the command in the terminal. Is there a way that I can either show the terminal, or set some sort of display to display the prompts?
Thanks!Would I be able to request that info and then place it into the terminal prompt?
Sure.
set username to text returned of (display dialog "Enter your username" default answer "Joe")
set password to text returned of ("Enter your password" default answer "" with hidden answer)
set theURL to "http://www.site.com/page.html"
do shell script "curl -u "& username & ":" & password & space & theURL
The idea here is to prompt the user for the data and combine the answer(s) with the static text that's passed to the shell.
Maybe you are looking for
-
How do I get an e-mail or couponthat does not fit entirely on the pqge moved tofit onthe page
-
How do I watch a rented movie on Apple TV
I rented a movie. Began to watch and had to stop. 15 minutes later, I went back to watch but cannot find rented movie.
-
One album will not import to authorized computer
I have a Macbook and an iMac. Both are set up to share, both are authorized in iTunes under the Apple ID I've had for years. I make all purchases on the Macbook. Then I copy them over to my iMac by selecting the Macbook under "Shared," choosing "Sho
-
Battery issue and warranty question
I bought my macbook pro in Dec 2007 and really love it. Fancy interface, easy usage. And after almost a year in Nov 2008, my battery went bad. Only last for 45 minutes, I check my serial and it said I'm still under warranty so I went to the nearest a
-
Deploying an application (.ear) from Visual Cafe
What is the easiest way to deploy an entire EJB application. I.e both the web and ejb parts from Visual Cafe. In JDeveloper you can just deploy the entire thing. But BEA has told me you have to deploy each part, then use ANT, then deploy again. Surel