Automator service in OSX High Sierra - macos

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

Related

How to close file picker dialog on mac with AppleScript?

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)

Unable to find the application support folder for a specified application inside an Apple Script

I have an apple script that asks the user to select an application as a prompt. I would like to know how it could be possible to find the directory of the Application Support folder for this application per example, Spotify is
~/Library/Application Support/Spotify/
On my mac, but like is there a way inside apple script to find this directory for the specific app. It would really be appreciated, thanks!
Because I would like to then delete this folder using Apple Script
This should accomplish what you're looking to achieve. Be careful though because using System Events to delete... deletes the item permanently instead of sending it to the Trash
property folderNames : missing value
tell application "System Events"
set appSupportFolder to application support folder
set folderNames to name of folders of appSupportFolder
set theChoice to my chooseFolderToDelete()
delete folder theChoice of appSupportFolder
end tell
to chooseFolderToDelete()
activate
set theChoice to (choose from list folderNames with prompt ¬
"Select an Application's Support folder to delete" OK button name ¬
"Delete Folder" cancel button name "Cancel") as text
end chooseFolderToDelete

Applescript click 'share dropbox link' using contextual menu

I am trying to access the 'share dropbox link' item the contextual menu of a specific file in a specific dropbox folder using AXShowMenu.
I have found the following script. Via Applescript right click a file
tell application "System Events"
tell process "Finder"
set target_index to 1
set target to image target_index of group 1 of scroll area 1
tell target to perform action "AXShowMenu"
end tell
end tell
Which seem to do the trick for desktop items,
but how can I use this to target specific files in folders then click the 'share dropbox link' in the contextual menu?
A little kludgey, but it does work. This requires you have the dropbox folder open and frontmost in Finder.
tell application "Finder"
activate --brings Finder to front
select item 1 of window 1 --selects the first item in the list ; not sure how you want to select/determine the item
end tell
delay 0.5 --this is to insure you don't get unwanted typing in script editor (makes sure Finder activates before kludgey typing gets done)
tell application "System Events"
tell application process "Finder"
set _selection to value of attribute "AXFocusedUIElement" --focused element (selected element)
tell _selection to perform action "AXShowMenu" --contextual menu
end tell
keystroke "share dropbox link" --type to select contextual menu item
keystroke return --select it by hitting return
end tell
[EDIT] Here's a trick to make sure your dropbox folder is open and frontmost in the Finder:
tell application "Finder"
activate --brings Finder to front
tell me to set dbFolder to POSIX file ((do shell script "cd ~/Dropbox/;pwd") & "/")
open dbFolder
select item 1 of window 1 --selects the first item in the list ; not sure how you want to select/determine the item
end tell
tell application "System Events"
tell application process "Finder"
set _selection to value of attribute "AXFocusedUIElement" --focused element (selected element)
tell _selection to perform action "AXShowMenu" --contextual menu
end tell
keystroke "share dropbox link" --type to select contextual menu item
keystroke return --select it by hitting return
end tell
There may be another way of selecting the contextual menu, but this is what I came up with so far late at night after a glass of wine.

Two dialogs followed with many choice in Applescript

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

Customize look of window dialog in 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

Resources