Here is the code :
tell application "Google Chrome"
activate
tell window 1 to tell active tab to print
tell application "System Events" to tell process "Google Chrome"
delay 1
tell window "Print"
click menu button "PDF"
delay 1
try
click menu item # of menu of menu button "PDF"
end try
end tell
end tell
end tell
Just replace the #
with the index of your script in the menu. (FYI : 1 is Open PDF in Preview
, 8 is Save PDF via Messages
The only way I can think of to achieve this without any 3rd party software is to do the following steps:
- Use Automator to create a service that runs an Apple Script
- Use System Preferences to assign a keyboard shortcut to the service
Below are the steps involved for each. Don't worry, the whole thing should only take 5-10 mins.
1. Create a service using Automator
- Launch Automator (usually found within your Applications folder)
- Go to File > New.
- Select Service and click Choose.
- In the top right hand of the window that appears, ensure that "No input" is selected from the Service receives drop-down list.
- Ensure the In drop-down list is showing "Any application".
- In the second column containing the long list, find "Run AppleScript" and double-click on it.
- This will add the Run AppleScript window on the right.
- Now, replace the ( Your script goes here ) with the following code:
set exceptionsList to {"HD1", "HD2", "HD3", "HD4"}
tell application "Finder"
set diskList to the disks
repeat with mountedDisk in diskList
if name of mountedDisk is not in exceptionsList then
eject mountedDisk
end if
end repeat
end tell
- In the first line of code, add your exceptions by changing the references to HD1, HD2, etc to any names of drives you do not want to eject. For example, HD1 should be replaced by your Macintosh HD (or whatever it's called). You may also want to add any Time Machine drives to the list, etc. You can add more by adding a comma and placing the name within quotes. Likewise, you can remove any you don't need.
- Save the service using a meaningful name (e.g. EjectAll).
Now to the next step.
2. Creating your shortcut
- Go to System Preferences > Keyboard > Shortcuts.
- Select Services from the sidebar.
- Find your service (it'll be in the list on the right-hand side).
- Add a shortcut by double clicking on the service name.
- Now go to System Preferences > Security & Privacy > Privacy.
- Select Accessibility in the sidebar.
- Click on the + sign (you may need to unlock the padlock if it's locked).
- Add Automator.
- Add Finder (to find this you will need to navigate to /System/Library/CoreServices/Finder.app).
- Exit your System Preferences.
Now you should be able to do two things:
1. Eject your drives from any application by going to the Services list within any Application menu (e.g. Finder > Services, Safari > Services, Mail > Services, etc) and select the service you just created. This will eject all drives not within your exception list.
2. Use the keyboard shortcut to run the service.
NOTE: I am aware that for some users keyboard shortcuts do not seem to work even though they've been assigned to a service. This is a whole other topic, but if this happens in your case, at least you should now be able to eject all drives from within any application you're using.
Hope this helps you and others.
Best Answer
The Shortcuts Prefs won't allow you to add the same Menu item twice, so no, this cannot be done.
Additionally, in Finder, the Copy menu item is a 'smart' structure, meaning it always contains the name or count of what would be copied by the key command. You cannot use the shortcut replacer at all on a smart menu.
Examples…
Furthermore, attempting to override a system-wide command like Copy is bound to fail somewhere. It's definitely best to stick to the system defaults for such as those.