Jump to content

How to paste as plain text?


Recommended Posts

Hi,

 

I am trying to write a script in python which would paste a random string.

It works normally, but when It tries to paste in iOS Simulator, it does not work.

 

If I try to paste by pressing "CMD + v" it does not work.

If I try to paste by pressing "CMD + SHIFT + v" it works.

 

Is there a way to simulate "CMD + SHIFT + v" instead?

 

Thanks.

Link to comment

I found a hacky way of using applescript for it instead.

tell application "System Events"
keystroke "v" using {command down, shift down}
end tell

This would simulate the "CMD" + "SHIFT" + "v" and paste the current text as plain text.

If anyone else has better ideas let me know.

 

Thanks.

Link to comment

This script does a better job. I had issues with the above.

on menu_click(mList)
	local appName, topMenu, r
	
	-- Validate our input
	if mList's length < 3 then error "Menu list is not long enough"
	
	-- Set these variables for clarity and brevity later on
	set {appName, topMenu} to (items 1 through 2 of mList)
	set r to (items 3 through (mList's length) of mList)
	
	-- This overly-long line calls the menu_recurse function with
	-- two arguments: r, and a reference to the top-level menu
	tell application "System Events" to my menu_click_recurse(r, ((process appName)'s ¬
		(menu bar 1)'s (menu bar item topMenu)'s (menu topMenu)))
end menu_click

on menu_click_recurse(mList, parentObject)
	local f, r
	
	-- `f` = first item, `r` = rest of items
	set f to item 1 of mList
	if mList's length > 1 then set r to (items 2 through (mList's length) of mList)
	
	-- either actually click the menu item, or recurse again
	tell application "System Events"
		if mList's length is 1 then
			click parentObject's menu item f
		else
			my menu_click_recurse(r, (parentObject's (menu item f)'s (menu f)))
		end if
	end tell
end menu_click_recurse

tell application "iPhone Simulator" to activate
menu_click({"iPhone Simulator", "Edit", "Paste Text"})

The menu selection script is taken from here

Link to comment

Nope. My bad. Above seems to work for Simulator only when Simulator is not focused for some reason.

 

This works:

tell application "System Events"
	tell process "iPhone Simulator"
		activate
		tell menu bar 1
			tell menu bar item "Edit"
				tell menu "Edit"
					click menu item "Paste Text"
				end tell
			end tell
		end tell
	end tell
end tell
Link to comment

 

Nope. My bad. Above seems to work for Simulator only when Simulator is not focused for some reason.

 

This works:

tell application "System Events"
	tell process "iPhone Simulator"
		activate
		tell menu bar 1
			tell menu bar item "Edit"
				tell menu "Edit"
					click menu item "Paste Text"
				end tell
			end tell
		end tell
	end tell
end tell

 

Copying to the clipboard with Alfred will do so as plaintext so, you could create a simple workflow that has a hotkey that sends the current selection to a Output->Copy to Clipboard and then use Cmd+v to paste normally. That would strip the formatting and paste as plain text

Link to comment

So I created a very simple workflow from a blank template:

 

Trigger:

Hotkey:CMD+SHIFT+V, 

Action: Pass through to workflow

Argument: OSX Clipboard Contents

 

Output:

Argument: {clipboard}

Check "Automatically paste to frontmost app"

 

Then when I copy anything, pressing cmd+shift+v does the job!

Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...