I've created a script that allows me to create folders and organize files for my work.
But i wish have a first dialog box asking me if I want to create a "web project" or a "graphic project". Then, according to my choice a second dialog box who give me several choices.
Explanations :
If I choose a "Web Project" in the first dialog box. This will open a second dialog box with several new choices.
Could you help me with this please ?
This is my first dialog box that i've created : (it works perfect)
set theName to (choose from list {¬
"Create Web Project", ¬
"Create Graphic Project"})
if theName is false then
display dialog "Cancelled." buttons {"Exit"} default button {"Exit"} with icon note
else
if first item of theName = "Create Web Project" then
set userResponse to (choose from list {¬
"Create Responsive Website Project", ¬
"Create Desktop Website Project", ¬
"Create Mobile Website Project", ¬
"Create Tablet Website Project"})
tell application "Finder"
set resPath to (path to me as text) & "Contents:Resources:Scripts:Web:" & userResponse & ".scpt"
set the_script to load script alias resPath
end tell
run script the_script
else if first item of theName = "Create Graphic Project" then
set userResponse to (choose from list {¬
"Create Basic Design Project", ¬
"Create Print Design Project", ¬
"Create ADS Banner Design Project"})
tell application "Finder"
set resPath to (path to me as text) & "Contents:Resources:Scripts:Graphic:" & userResponse & ".scpt"
set the_script to load script alias resPath
end tell
run script the_script
end if
end if
EDITED: i've edited my code inspiring by your code. It works but i don't have the good alerts box !
Try:
set theName to (choose from list {¬
"Create Web Project", ¬
"Create Graphic Project"})
if first item of theName = "Create Web Project" then
set userResponse to choose from list {"A", "B"}
else if first item of theName = "Create Graphic Project" then
set userResponse to choose from list {"C", "D"}
end if
Related
I have file picker in my macos application that works through AppleScript command:
choose file of type {"", "png", "jpeg", "jpg"} with prompt ""
The problem I currently have is that users can open multiple file picker dialogs at once. I am looking for a way to close all of the opened file picker dialogs before opening a new file picker dialog but I have not no progress with this.
Is there any way to close previously opened file picker dialogs?
Following script will close "Choose File" dialogs of all instances of your app opened before.
set processName to "Script Editor" -- edit here the name of your app
tell application "System Events"
repeat with aProcess in (processes whose name is processName)
set frontmost of aProcess to true
try
click button "Cancel" of window "Choose a File" of aProcess
end try
end repeat
end tell
NOTE: to test the script above with "Script Editor", you should open 2 instances of "Script Editor" (with single "choose file" code line) then open 3rd instance of "Script Editor" with script above and run all of them. First, run 2 firstly created instances.
You can open the instances of Script Editor (or, other app) with this helper script:
use framework "AppKit"
use framework "Foundation"
use scripting additions
set theApp to choose application
set appPath to POSIX path of (path to theApp)
set appURL to current application's class "NSURL"'s fileURLWithPath:appPath
set theWorkspace to current application's class "NSWorkspace"'s sharedWorkspace()
set startOptions to current application's class "NSWorkspaceOpenConfiguration"'s configuration()
set startOptions's activates to true
set startOptions's createsNewApplicationInstance to true
theWorkspace's openApplicationAtURL:appURL configuration:startOptions completionHandler:(missing value)
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
I've worked out (found online) how to attach a single item from Finder to a new Outlook message. I've played with this format a good amount - changed 'selecteditem' and selection and some other more major changes - but I can't work out how to get more than one item to attach to a new outlook message at a time.
Only a single item attaches to each new outlook message. There are no Outlook Automator options in Automator - I think Office 365 did away with them.
My current script is as follows:
tell application "Finder" to set selectedItem to item 1 of (get selection)
set theAttachment to selectedItem as alias
set fileName to name of selectedItem
tell application "Microsoft Outlook"
set newMessage to make new outgoing message with properties {subject:fileName}
tell newMessage
make new attachment with properties {file:theAttachment}
end tell
open newMessage
get newMessage
end tell
I'm currently trying use this script in Automator as a service so I have a right click option to send files directly to a new Outlook message. It's currently setup like this.
Your Automator Service gets "Files or Folders" from Finder. This part is OK. Just the content of the applescript must be changed.
To read these inputs (the selected files from Finder), you must use the "on run" handler where "input" will be the selected files.
The script bellow must replace your current script. I assumed that the subject of your email should be the name of the first selected file in case of multiple selection:
on run {input, parameters}
set SelectedItems to input
tell application "Finder" to set fileName to name of first item of SelectedItems
tell application "Microsoft Outlook"
set newMessage to make new outgoing message with properties {subject:fileName}
tell newMessage
repeat with aFile in SelectedItems -- the loop through all selected items
make new attachment with properties {file:aFile}
end repeat
end tell
open newMessage
get newMessage
end tell
return input
end run
On top of that, I have 2 comments :
1) this script does not filter the case when you select a folder. Inside the loop, you may want to add a "if" test to check file or folder and take action in case selection is a folder.
2) I do not understand the overall process you want to perform: Select files, go to menu Service to run this service, which creates a new Outlook message with these files as attachment...You can do all this by just selecting the files and drag/drop them on the Outlook icon in the dock. it will immediately create a new blank message with all the attached files.
Old question, but I ran into this today and used the "Shortcuts" app on MacOS to get this working, or at least something similar.
Start to finish:
Opened Shortcuts app on MacOS (Monterey)
Select (+) to create new shortcut
Searched for and select "Run AppleScript"
Highlight Text in script and replace with below:
on run {input, parameters}
set SelectedItems to input
tell application "Finder" to set fileName to name of first item of SelectedItems
tell application "Microsoft Outlook"
set newMessage to make new outgoing message with properties {subject:fileName}
tell newMessage
repeat with aFile in SelectedItems -- the loop through all selected items
make new attachment with properties {file:aFile}
end repeat
end tell
open newMessage
get newMessage
end tell
return input
end run
On the top right of the Shortcuts window select the Shortcut Details (Adjustable Bars Icon)
Select "Pin in Menu Bar", "Use as Quick Action", "Finder" & "Services Menu".
Under the "Run AppleScript with" select "Shortcut Input".
It should look like this:
And this is how you use it within the Finder:
If outlook is open, it will attach it like shown:
I want to disable the private browsing using apple script
before i run the disable code i want to make sure PrivateMode is enabled
for disabling i use following apple script
tell application "System Events"
tell process "Safari"
click menu item "Private Browsing" of menu 1 of menu bar item "Safari" of menu bar 1
end tell
end tell
The problem is that if i run this script and private browsing is not activated it will activate the private mode.
So i want the check to detect if private mode is enabled .So only then i will call the above apple script
Thanks
Use the "AXMenuItemMarkChar" attribute to get the checked of a menu item.
tell application "System Events"
tell process "Safari"
tell menu item "Private Browsing" of menu 1 of menu bar item "Safari" of menu bar 1
if value of attribute "AXMenuItemMarkChar" is "✓" then click -- disabling
end tell
end tell
end tell
Updated:
To not open an application (AppleScript applet or droplet) to the foreground : Use this script to add the property LSBackgroundOnly in the Info.plist of the bundle (the applet).
set tApp to choose file with prompt "Select your application (applet AppleScript)"
set tPlist to quoted form of ((POSIX path of tApp) & "Contents/Info")
do shell script "/usr/bin/defaults write " & tPlist & " LSBackgroundOnly -bool TRUE"
do shell script "/usr/bin/defaults write " & tPlist & " LSUIElement -bool TRUE"
Fun fact:
Running Safari on a German system, the menu item title "Private Browsing …" switches to "Private Browsing" (without the three points). It is impossible to switch private browsing on and off with the same handler
tell application "System Events"
tell process "Safari"
try
-- turn Private Browsing on
click menu item "Privates Surfen …" of menu 1 of menu bar item "Safari" of menu bar 1
-- turn Private Browsing off
click menu item "Privates Surfen" of menu 1 of menu bar item "Safari" of menu bar 1
end try
end tell
end tell
I don't have an English system here, maybe there is such title switch on your system, too?
Michael / Hamburg
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