求适用于macOS Sierra的Automator服务Apple脚本:带引号粘贴纯文本
Hey there! I’ve got a straightforward, reliable solution for building that Automator service you need for macOS Sierra—perfect for streamlining your PDF quote workflow in Scrivener and other writing apps. Let’s walk through this step by step.
Step 1: Create a New Automator Service
- Open Automator (find it in your Applications folder or via Spotlight search)
- When the template selector pops up, choose Service and click Choose
- At the top of the workflow window, configure the service settings:
- Set Service receives selected to text
- Set in to any application (this lets you use the service across Scrivener, Pages, and more)
Step 2: Add the AppleScript Action
- In the left-hand Actions library, search for Run AppleScript and drag it into the main workflow area
- Replace the default sample code with this custom script (it handles all your requirements):
on run {input, parameters} -- Grab the raw text from your clipboard set rawText to the clipboard as text -- Remove all line breaks (replace with spaces to keep words connected) set cleanedText to replace_chars(rawText, linefeed, " ") set cleanedText to replace_chars(cleanedText, return, " ") -- Clean up any extra spaces created by multiple line breaks set cleanedText to replace_chars(cleanedText, " ", " ") -- Wrap the cleaned text in double quotes set quotedText to "\"" & cleanedText & "\"" -- Put the final text back into the clipboard as plain text set the clipboard to quotedText -- Simulate the paste command to insert into your active writing app tell application "System Events" keystroke "v" using command down end tell return quotedText end run -- Helper function to replace text strings consistently on replace_chars(this_text, search_string, replacement_string) set AppleScript's text item delimiters to the search_string set the item_list to every text item of this_text set AppleScript's text item delimiters to the replacement_string set this_text to the item_list as string set AppleScript's text item delimiters to "" return this_text end replace_chars
Step 3: Save the Service
- Click File > Save and give it a descriptive name like "Paste Quoted Plain Text from PDF"
- The service will automatically save to
~/Library/Services/so it’s accessible across your apps
Step 4: Use the Service (With a Keyboard Shortcut for Speed)
- Copy text from your PDF as usual (
Cmd+C) - Switch to Scrivener (or your other writing app) and place your cursor where you want the quote
- You can use the service in two ways:
- Go to the app’s menu bar: [App Name] > Services > [Your Service Name]
- Recommended: Set a custom keyboard shortcut to save time:
- Open System Preferences > Keyboard > Shortcuts > Services
- Find your service under the Text category
- Click the empty space next to it, then press your desired key combo (e.g.,
Cmd+Opt+V)
Scrivener-Specific Notes
- Scrivener’s built-in Paste and Match Style behavior works seamlessly with plain text pastes, so your quoted text will automatically adopt the style of the paragraph you’re pasting into—no extra formatting cleanup needed.
- If you run into PDFs with weird line breaks (like those split for page margins), the script already handles replacing all line breaks with spaces to keep your quote flowing naturally.
内容的提问来源于stack exchange,提问作者Akos
相关产品推荐
相关产品推荐

