Customize look of window dialog in AppleScript? - applescript

i would like to know if it's possible to change the look of Dialog Window in Applescript, for example change the icon (note, stop, caution) by a custom picture or icon instead.
And if it is possible to change the typography (alignment, font, bold ... etc.)
If yes, could you help me with an example for my code or provided a link to a good tutorial please!
set folderName to text returned of (display dialog "Please enter new folder name:" default answer "Folder_Name")
set loc to choose folder "Choose Parent Folder Location"
try
tell application "Finder"
set newFolder to make new folder at loc with properties {name:folderName}
end tell
display dialog "Successfully! Want to reveal the new folder?" with icon note buttons {"Cancel", "Go to my new folder"} default button "Go to my new folder" cancel button "Cancel"
if button returned of the result = "Go to my new folder" then
tell application "Finder"
reveal newFolder
activate
end tell
end if
end try

You can't change the typography. However you can use:
display dialog "hi" with icon withIconFile
where withIconFile is an alias or file reference to a ‘.icns’ file

This is better for me !
display dialog "My custom icon " buttons {"Cancel", "Continue"} default button "Continue" with icon file "Path:to:my.icon.icns"

You can also do:
display dialog "Hello" buttons {"Cancel", "Continue"} with icon {"/Users/" & (do shell script "whoami") & "/path/to/picture.jpg"}
The do shell script part just makes it work, even if you send it to your friends, although I would then recommend downloading the image from the internet with curl and placing it in a folder. Sorry if it is a bit confusing

Related

Applescript: Open a new Safari tab from a display dialog box

I would like to open a new tab on Safari from a display dialog box with a dynamic URL
Basically only the last digits of the URL are changing, the end has to come from the user
## dialogue box##
set theResponse to display dialog "Show me the ID" default answer "" with icon note buttons {"Cancel", "Continue"} default button "Continue"
## Open URL##
set myURL to "https://myURL/"
on open location myURL
set URL to myURL & theResponse
tell application "Safari" to open URL
end open location
The box works perfectly and I see in the Script Editor that the results is taken into account:
tell application "Script Editor"
display dialog "Show me the ID" default answer "" with icon note buttons {"Cancel", "Continue"} default button "Continue"
{button returned:"Continue", text returned:"123456"}
I'm just not sure how to open the URL from 2 different sources and what format I should use
If there are only a couple of URLs you could just use buttons, for example `{"Cancel", "Continue with X", "Continue with Y"}, and use different URLs based on the button and text returned.
on run
set response to (display dialog "Show me the ID" default answer "" with icon note buttons {"Cancel", "Continue with X", "Continue with Y"} default button "Continue with Y")
if button returned of response is "Continue with X" then
set baseURL to "https://URLx/"
else -- Continue with Y
set baseURL to "https://URLy/"
end if
openNewTab(baseURL & text returned of response)
end run
on openNewTab(myURL)
tell application "Safari"
activate
tell window 1 to set current tab to (make new tab with properties {URL:myURL})
end tell
end openNewTab

Automator service in OSX High Sierra

Automator service at the active finder window. The idea is to create a folder template at the active finder window with choosing the new folder
dialog.
Service:
ask for folder name
make new folder
run shell script
The Automator service fails and I am not sure why. The path of the active finder window is not reaching the variable thePath which is assigned to the new folder Automator action.
The screen shots displays a simplified version of the service and the error.
Can I get idea of what is wrong?
Try inserting this code in a run AppleScript action, into your workflow.
set theName to text returned of (display dialog ¬
"INSERT A NEW FOLDER NAME" default answer ¬
"Enter Desired Name Of New Folder" hidden answer false ¬
buttons {"Cancel", "OK"} ¬
default button ¬
"OK" cancel button ¬
"Cancel" with title ¬
"CHOOSE A NAME" with icon 1 ¬
giving up after 30)
tell application "Finder"
set currentTarget to target of window 1 as alias
set the name of (make new folder at currentTarget) to theName
end tell

Applescript application and Open with

I have a simple script
on run
display dialog "Hello" buttons {"Ok"}
end run
I saved it as application (let's say myapp.app)
If I just launch it from finder by double clicking then it works (i.e. shows the dialog box), but I want to use it for opening files.
The problem:
For example I have file.xyz, then right-click it to "open with" and choose my.app. In this case my.app doesn't start (no icon at the dock panel, no dialog box shown).
You can use an open handler to drag items on the application like this:
on open of theFiles
-- Executed when files are dropped on the application
display dialog "There are " & (count of theFiles) & " files dropped" buttons {"OK"}
end open

How to get selected text in Word 2011 within Applescript

I want to get the selected text in the active document in Word 2011 from Apple-Script.
Thanks
Try:
tell application "Microsoft Word" to get selection's content
I've tried this, and it works
tell application "Microsoft Word"
activate
try
set selectedText to content of text object of selection
display dialog selectedText buttons {"OK"}
on error
display dialog "erreur" buttons {"OK"}
end try
end tell

Show something in a finder window

Ok, I am trying to make a script where you type something and a new finder window appears with what you typed in it. Similar to spotlight search, but in a script.
set theFind to text returned of (display dialog "What do you want to find?" default answer "" buttons {"Cancel", "Ok"} default button 2)
tell application "Finder"
reveal theFind
end tell
There’s an AppKit method that does exactly what (I think) you’re asking for: -[NSWorkspace showSearchResultsForQueryString:], which means you can use it using AppleScriptObjC. So, in AppleScript Editor, File > New from Template > Cocoa-AppleScript Applet, then:
property NSWorkspace : class "NSWorkspace"
NSWorkspace's sharedWorkspace()'s showSearchResultsForQueryString_(theFind)
Alternatively, you could skip AppleScriptObjC and use the hidden Finder command that that method uses:
tell application "Finder" to «event aevtspot» theFind

Resources