i'm writing a script that needs to copy and paste text from an entry in a dialogue box
set query to text returned of (display dialog "Enter Text" default answer "" buttons {"Input", "Cancel"} default button 1)
query
tell application "System Events"
keystroke "c" using command down
keystroke "v" using command down
end tell
when i run this script it copies and pastes "set query to text..."
how can I copy the query that I entered ? i'm going to paste the text somewhere else later but I need to figure out how to actually copy the text. I was using keystroke query but that was taking a long time when the strings were long
Use set the clipboard:
display dialog "" default answer ""
set the clipboard to text returned of result
If others get here searching for how to for example copy a long error message from a dialog shown by OS X, you can use Accessibility Inspector, which is in /Applications/Xcode.app/Contents/Applications/.
Related
I'm writing a language extension and I need to know what the current selection inside the completion prompt is
example
For example, in the b, d options in the figure, I need to automatically fill the selected CompletionItem.label characters to before the / character after entering the / character, please help, I have been looking for several hours
Using executeCommand can only get the return value, and the editor will not display the selection
vscode.commands.executeCommand("vscode.executeCompletionItemProvider", ...)
I have tried to monitor the up and down direction buttons, but I found that using the contributes.keybindings in package.json to bind the buttons will cause the cursor movement to fail
The ultimate goal is to add the string current selection/ to the editor after entering the / character
This is a similar effect, I only entered ., without pressing Enter
enter image description here
This is the error that pops up when I try my script out:
Script Error ---- Can’t make {button returned:"Enter", text returned:"testing"} into type Unicode text.
I'm trying to have users enter a Username so that they that have their Documents folder be linked to a file server.
I have that part separate but now on this part of having the user input their username so when I have ln -s /Volumes/Drive/Documents Documents the username will automatically pull from the script and input it by itself so the Documents folder and File server could be linked.
Basically trying to make it to where the user doesn't have to go into the terminal and link the two together. I'm not sure why the error code is popping up other than it is probably having to deal with the set Username part of the script so not completely sure.
set Username to (display dialog "Enter your NetID Username" default answer "" buttons {"Cancel", "Enter"} default button 2)
tell application "Terminal"
activate
do script "'ln -s /Volumes/Drive/Documents Documents'" & Username
end tell
return input
The error message
Can’t make {button returned:"Enter", text returned:"testing"} into type Unicode text.
is pretty clear.
display dialog returns a record, not a string so you have to write
set Username to text returned of (display dialog "Enter your NetID Username" default answer "" buttons {"Cancel", "Enter"} default button 2)
Or if you need to handle the button and the returned text write
set {button returned:buttonReturned, text returned:textReturned} to display dialog "Enter your NetID Username" default answer "" buttons {"Cancel", "Enter"} default button 2
Is there any way, plugin, macro or something to make Sublime Text 3 automatically select the text that was just pasted?
I need to copy and paste some JSON data, but the pasted text is never in line with the surrounding text. Paste and indent -feature does not work properly for this.
What does work is the reindent feature, but it requires me to select a block of text and pressing a hotkey. So after pasting I would benefit for having the just pasted block of text being automatically selected, so I can just press the reindent hotkey to properly indent what I pasted.
Furthermore, it would be even better if I could bind the whole process to a hotkey, so:
Select text
Copy
Press some self defined hotkey to run a macro(?)
This macro the pastes the text, selects the pasted text and runs the reindent hotkey (*)
*So basically I would like to make a keybinding, say, ctrl+shift+b to do the following:
ctrl+v
Somehow select pasted text
ctrl+shift+f
You can create a plugin to do this, and execute it with a keybinding:
from the Tools menu -> Developer -> New Plugin...
select all and replace with the following
import sublime
import sublime_plugin
class PasteAndReindentCommand(sublime_plugin.TextCommand):
def run(self, edit):
before_selections = [sel for sel in self.view.sel()]
self.view.run_command('paste')
after_selections = [sel for sel in self.view.sel()]
new_selections = list()
delta = 0
for before, after in zip(before_selections, after_selections):
new = sublime.Region(before.begin() + delta, after.end())
delta = after.end() - before.end()
new_selections.append(new)
self.view.sel().clear()
self.view.sel().add_all(new_selections)
self.view.run_command('reindent')
save it, in the folder ST suggests (Packages/User/) as something like paste_and_reindent.py
add the following to your User keybindings { "keys": ["ctrl+shift+b"], "command": "paste_and_reindent" },
Note that Ctrl+Shift+B will replace the default binding for "Build With".
How it works:
when the keybinding is pressed, it runs the new command created in the plugin
this stores the current text selection positions
then it performs the paste operation
then it gets the new text caret positions
then it compares the old positions to the new ones, and selects the text that was pasted
then it runs the reindent command
You could get it to clear the selections again afterwards (by repositioning the text carets to the end of the selections - i.e. the default behavior after pasting) by doing another comparison of the selections before and after the reindentation.
On MacOS you can add:
"find_selected_text": true
to Sublime Text->Preferences->Settings (User Settings View)
I am going nuts here. I have tried countless permutations/variations of "save as active document file format PDF" but none seem to work. I get AppleScript errors with all of them.
So can anyone tell me:
What is the exact syntax to save the active document as a PDF file in AppleScript, using Word?
It seems that there is no coherence whatsoever in the Office for Mac scripting, as I have this working for Excel and PowerPoint and even there the syntax is different:
excel
save active workbook in 'MyFile.pdf' as PDF file format
PowerPoint
save active presentation in 'MyFile.pdf' as save as PDF
What is the correct syntax for Word?
Thanks!
It seems I found it after all:
set myDoc to "/Users/X/Desktop/test.docx"
set pdfSavePath to "Users:X:Desktop:test.pdf"
tell application "Microsoft Word"
activate
open myDoc
set theActiveDoc to the active document
save as theActiveDoc file format format PDF file name pdfSavePath
end tell
I am no AppleScript expert. I had slashes instead of : as path separators. With : it works
Joris Mans script is pretty nice, but has a flaw. It does not ensure that Word has an active document ready (set theActiveDoc to the active document might return missing value)
I also improved the script to use the Finder selection as input, placing the PDFs into the same place as the word files. I did not test the file types, but word will complain about that.
tell application "Finder"
set input to selection
end tell
tell application id "com.microsoft.Word"
activate
repeat with aFile in input
open aFile
set theOutputPath to ((aFile as text) & ".pdf")
repeat while not (active document is not missing value)
delay 0.5
end repeat
set activeDoc to active document
save as activeDoc file name theOutputPath file format format PDF
close active document saving no
end repeat
end tell
I'm new to n++, but I have been most impressed with this tool so far. I've been trying to record a macro that do a search/replace, but the 'search' part seems to have the initial search text from the recording 'hard-coded' in the macro.
What I want is:
Manually locate the cursor at the beginning of the first line of a fixed format code segment, then Macro actions:
move cursor two lines down
move cursor right x characters
mark charters from pos x to x+n
search and replace all occurrences of the selected text with "{p_'selected text'}"
In an more advanced version, I'd like to add some logic to step 4: only execute the replace part if the # of occurrences are > 1 (e.g. by first adding a count statement, but I'm not sure how to obtain the returned count # from the dialog box)
Is this possible?
While I'm a big fan of Notepad++, this sounds like something I would accomplish with AutoHotKey. You would select the text and copy it to the clipboard. AutoHotKey would read the clipboard, replace the text as you desire, and either replace the clipboard contents, or send it back to your document. Let me know if you would like to go that route.