How to make an applescript into a service?
I don't see any way to create a service from within Big Sur's Script Editor. Am I missing something?
TIA,
David
You can make a difference in the Apple Support Community!
When you sign up with your Apple Account, you can provide valuable feedback to other community members by upvoting helpful replies and User Tips.
When you sign up with your Apple Account, you can provide valuable feedback to other community members by upvoting helpful replies and User Tips.
I don't see any way to create a service from within Big Sur's Script Editor. Am I missing something?
TIA,
David
Ok. I have a working Automator application using the GUI scripting code that I posted in your previous post. I added a Get Specified Finder Items action to use the name of a text file containing the list of cookies you want to remove from Safari. This way, you only have to edit this cookies.txt file and not the hard-coded list within the AppleScript code.
Because of the increased security measures in recent operating systems, there are some System Preferences : Security & Privacy additions one must make to avoid annoying restriction dialogs apppearing, and the ability to actually send keystrokes from an Automator application.
First, launch Automator from your Applications folder, Choose new Document, and select Application, then click Choose. Next, you only need to drag and drop the following actions from the libary, and in order onto the larger workflow window:
The Run AppleScript action will default to a boilerplate on run handler. Select and remove everything in this Run AppleScript action. Then replace with the following code:
use scripting additions
on run {input, parameters}
# input is the name of the file passed in from Get Specified Finder Items
# read the contents of the input text file and automatically generate a list of cookies to remove
set deCookie to (read file (input as text) as text using delimiter linefeed) as list
# Safari must be running before this script can work properly
tell application "Safari" to if it is not running then activate
tell application "System Events"
tell application process "Safari"
set frontmost to true
keystroke "," using command down
delay 1
tell window 1
click button "Privacy" of toolbar 1 of it
try
repeat with d in deCookie
click button "Manage Website Data…" of group 1 of group 1
-- give cookies time to load in their scrollable window
delay 2
select -- focuses on the search window
try
keystroke d
delay 2
select row 1 of table 1 of scroll area 1 of sheet 1
delay 1
click button "Remove" of sheet 1
end try
end repeat
click button "Done" of sheet 1
on error errmsg number errnbr
click button "Done"
keystroke "w" using command down
display alert "No cookies to remove" giving up after 5
return
end try
end tell
keystroke "w" using command down
display alert "Selected cookies removed" giving up after 5
end tell
end tell
# because if you don't do this, the next time you open Preferences it will be hung
tell application "Safari" to if it is running then quit
return
end run
Click the hammer icon within the Run AppleScript action to compile the AppleScript code, and then you can save the Automator Application to your Desktop. I gave mine the name Remove_Cookies, and I would resist using white-space in the application name.
Now, you have some security work to do before you can run it. Open System Preferences : Security & Privacy with your administrator password. Do the following:
Now, once you have built your text file of cookies to remove, you can double-click the saved Automator application on your Desktop and the familiar Safari Privacy panel antics will appear for each cookie that you have added to the cookie.txt file. If you need to edit your saved application, just launch Automator, and select open Recent.
It has script editor but there's no save to services feature in Mavericks that I can see. I just save my Applescript, use Automator to turn it into a workflow, then I think I moved that manually to my Services folder. I don't remember exactly since I did this once about 3 years ago to turn some of my F keys into tray open and close keys for an external drive on an iMac. The eject on my keyboard didn't work with external drives.
One launches Automator, and in Big Sur, chooses Quick Action (aka Service) to create a service workflow. Then from the Utilities library, select Run AppleScript and drag it onto the right-hand workflow window. You would insert your AppleScript within the on run clause, and what every you selected for the service to action would be in the input variable. You then save the Quick Action with a short, but meaningful name (without any extension) and it is written into your /Users/yourname/Library/Services folder.
Automator solutions are workflows in that the output of one action flows into the input of another like a waterfall. It is best to get the AppleScript code working in Script Editor where you can see when things go wrong, as there is no such debugging capability in Automator. One syntax error and it just quits with no helpful message why.
If you can explain what you are attempting to construct for a specific outcome, you might get more guidance on how to proceed.
Thanks for this. I'm not quite sure what you mean by 'what ever [sic] you selected for the service to action would be in the input variable'. The script I'll be embedding deletes specific cookies from Safari.
TIA,
David
Sorry, kind of fried and didn't pay attention to your name. I probably would not create a service (Quick Action) for what you are trying to do, but rather an Automator application that would simply run, remove the selected cookies from Safari, and then quit. Application sits on your Desktop, where you just double-click it to run the cookie removal functionality.
Let's see if I can whip up something here for you.
When you save the completed Application workflow from Automator, use the name Remove_Cookies and see if it will handle that name without grief. I have no idea how this can be related to Xode or the separate command-line tools for Xcode error dialog.
What's going on with that Automator application progress? I would reboot the Mac, and start over following my instructions from the beginning (e.g. launch Automator and choose Application, etc.
I have been creating and saving Automator applications for years on Macs with no developer tools installed, and those with Xcode and/or the command-line developer tools installed, and have never once seen the Automator error dialog that you posted.
I recommend that you start over with a clean approach by launching Automator, choose the Application category, and click Choose. Now, follow the same steps as I outlined above in my Jan 5 post. At any point, if you have a question, ask away.
Are you running a released Big Sur 11.1?
And here is what the finished Automator application looks like before it is saved:
This is awesome! I'm not able to save the application however (and thus couldn't take the last steps you mentioned yet). I get this error msg:
Thoughts?
I don't use Big Sur so I don't know what has changed. On Mavericks I use the Applescript in an Automator worksflow and save the workflow in my user directory > Services folder.
Does Mavericks have Script Editor? I see no say to doing what you describe in SE.
I get the same error.
Sorry but I had a difficult time to get into Apple communities yesterday...go figure.
I re-booted and re-tried your approach and unfortunately got the same error.
Thoughts?
How to make an applescript into a service?