I can use AppleScript to send ExtendScript to Photoshop and get back the result:
This sends "2" to stdout:
tell application "Adobe Photoshop CC 2017"
do javascript "var x = 2; x"
end tell
I get a syntax error when I try the same thing for InDesign 2015:
This results in a syntax error: Expected end of line but found application constant or consideration.
tell application "Adobe InDesign CC 2015"
do javascript "var x = 2; x"
end tell
This similar code, using script instead of javascript does slightly better, resulting in this error message: Adobe InDesign CC 2015 got an error: A identifier can’t go after this identifier.
tell application "Adobe InDesign CC 2015"
do script "var x = 2; x"
end tell
Any suggestions for getting this to work?
The main difference is that "do script" is a specific command of the InDesign Scripting model in Applescript so its syntax is specific.
set myJavaScript to "var x = 2; x"
do script myJavaScript language javascript
Related
Using Xcode, I'm trying to pipe the output of a shell command that I use to check the list of available printers on a print server. It works in Terminal, but the output can only be seen in the debugger, and when I put the script into Script Editor, I get the output displayed as a "Syntax Error".
I'm trying to have it come up as an alert with the Display alert command but I've had no luck.
on Button_(sender)
set Printerlookup to "/usr/local/bin/iprntcmd --listprintersonserver printerserver.com"
set Printers to do shell script Printerlookup
display alert "The available printers are:" & Printers
end Button_
EDIT:
This is the whole appdelegate.
script AppDelegate
property parent : class "NSObject"
property txtBox: ""
-- IBOutlets
property theWindow : missing value
on applicationWillFinishLaunching_(aNotification)
-- Insert code here to initialize your application before any files are opened
end applicationWillFinishLaunching_
on applicationShouldTerminate_(sender)
-- Insert code here to do any housekeeping before your application quits
return current application's NSTerminateNow
end applicationShouldTerminate_
use scripting additions
on Button_(sender)
if txtBox is "" then
display alert "Please enter some text"
else
set iPrntlookup to "/usr/local/bin/iprntcmd --listprintersonserver "& txtBox &"printerserver.com"
set Printers to do shell script Printerlookup
display alert "The available printers are:" & Printers as text
end if
end Button_
end script
This is the expected output, which is found in the debugger area as opposed to the dialog box.
2018-05-07 21:34:12.925412+1000 iPrint Local[29523:430596] MessageTracer:
Falling back to default whitelist
2018-05-07 21:34:17.104407+1000 iPrint Local[29523:430596] *** -[AppDelegate
Button:]: iprntcmd v06.07.01
Listing printers on testprintserver.com.
ipp://testprintserver.com/ipp/printer1
ipp://testprintserver.com/ipp/printer2 (error 1)
Add a use scripting additions statement at the top of your script.
I am new to haskell but I'm trying to run a program with the Gloss library. I have installed it the library and all its dependencies with no problems, can compile a file with the Gloss library imported, but when I try to actually run a test program like this one (my typing "main" in ghci after the file is loaded):
-- | Display "Hello World" in a window.
--
import Graphics.Gloss
main
= display
(InWindow
"Hello World" -- window title
(400, 150) -- window size
(10, 10)) -- window position
white -- background color
picture -- picture to display
picture
= Translate (-170) (-20) -- shift the text to the middle of the window
$ Scale 0.5 0.5 -- display it half the original size
$ Text "Hello World" -- text to display
I end up getting the following text in ghci (version 8.0.1):
*** Exception: user error (unknown GLUT entry glutInit)
I have googled this problem but all solutions seems to be if you are on windows you should add some dll file glut32.dll. But I'm on OS X Mavericks so what do I do to make it work? Can anyone help with getting Gloss programs to run on OS X? I don't even understand what "unknown GLUT entry glutInit" means. Thanks a lot!
I'm adding AppleScript support to my macOS application but I have problems accessing a property of an object I defined.
The sdef file resulted in the following directory:
When I run the following script:
tell application "Daily"
get all activities
end tell
I get this result:
However, when I run this script:
tell application "Daily"
repeat with iActivity in (get all activities)
name of iActivity
end repeat
end tell
I get this error:
error "Daily got an error: Can’t make «class » id \"E10E6A7B-6D3B-464B-9C31-35DB6763C492\" into type specifier." number -1700 from «class » id "E10E6A7B-6D3B-464B-9C31-35DB6763C492" to specifier
Any idea what I am doing wrong? Thanks!
I want my program to launch another desktop application.
Tried shell execute (open appname) but it does not work.
Is there another way ?
Thank you in advance.
Another possibility is use the standard Xojo FolderItem and use the Launch method.
Dim f as folderitem = specialfolder.applications.child("AppName")
if f <> nil and f.exists then
f.launch
end
Reference Documentation:
http://docs.xojo.com/index.php/SpecialFolder
http://docs.xojo.com/index.php/FolderItem.Launch
dim s as new Shell
s.Execute("open -a ""Finder""")
' Check error code and do something about it...
if s.ErrorCode <> 0 then
MsgBox("Error code: " + Str(s.ErrorCode) + EndOfLine + "Output: " + s.Result)
end if
Change "Finder" to whichever application you need, or build a string and pass that to s.Execute(). Be sure to include escaped quotes, especially if the application has spaces in its name.
I'm not familiar with Xojo, however "launching" an application on OS X is complicated. There are many things you need to consider, especially if it's already running.
I recommend you look into two possible options, either use Xojo's ability to launch call native C code to run one of the three -[NSWorkspace launchApplication...] methods: https://developer.apple.com/library/mac/documentation/cocoa/reference/applicationkit/classes/NSWorkspace_Class/Reference/Reference.html#//apple_ref/doc/uid/20000391-SW23
Alternatively, use Apple's open command line tool:
/usr/bin/open -a "App Name"
/usr/bin/open -a "/Applications/App Name.app"
I've created an applescript to boot from snow leopard to lion, but the bless command is failing. Here's the command:
do shell script "bless -mount /Volumes/bootdrive/ -legacy -setBoot -nextonly" password "mypassword" with administrator privileges
On reboot, I get the black screen with 'No bootable device' error. I've run the command directly in the terminal as root (rather than as an applescript) and have gotten the same result. And yes, I've triple-checked that the disk path I'm using is correct and is bootable.
Any idea what the issue could be?
I don't have an appropriate setup to test with, but the -legacy option looks very suspicious to me. According to the man page, that's used to support BIOS-based operating systems, which OS X isn't. Try removing -legacy and see if it works better.
Working solution
The SIP was the first problem I've encountered on Big Sur. Turned it off looks like a bad idea. The second problem was target volumes list items doesn't have actions. Which make impossible to click on them via click or "click at" functions perhaps because of some new additional protections on Big Sur. Click with AST and other scripts also doesn't works due to new MacOS restrictions. The only way I found is using python click(but this leads to a slight delay while script selects target volume).
So here is a fully automated switching:
property targetVolume : "BOOTCAMP" # find name of required volume inside System Preference > Startup Disk
property passwordValue : "yourSystemPassword" # Can be empty
tell application "System Events"
tell application "System Preferences"
set current pane to pane id "com.apple.preference.startupdisk"
activate
end tell
tell application process "System Preferences"
tell window "Startup Disk"
set volumePosition to {0, 0}
set lockFound to false
# Check if auth required
set authButtonText to "Click the lock to make changes."
if exists button authButtonText then
click button authButtonText
# Wait for auth modal
set unlockButtonText to "Unlock"
repeat
if (exists sheet 1) and (exists button unlockButtonText of sheet 1) then exit repeat
end repeat
# Autofill password if setted
if passwordValue is not equal to "" then
set value of text field 1 of sheet 1 to passwordValue
click button unlockButtonText of sheet 1
end if
# Wait for auth success
repeat
if exists button "Click the lock to prevent further changes." then exit repeat
end repeat
end if
# Wait until loading volumes list
repeat
if exists group 1 of list 1 of scroll area 1 then exit repeat
end repeat
# Click on target volume (posible a slight delay because of shell script executing)
repeat with m in (UI element of list 1 of scroll area 1)
if (value of first static text of m = targetVolume) then
tell static text targetVolume of m
set volumePosition to position
end tell
end if
end repeat
set volumePositionX to item 1 of volumePosition
set volumePositionY to item 2 of volumePosition
my customClick(volumePositionX, volumePositionY)
click button "Restart…"
# Wait for restart modal appears
repeat
if (exists sheet 1) and (exists value of first static text of sheet 1) then exit repeat
end repeat
click button "Restart" of sheet 1
end tell
end tell
end tell
# shell script to make click work on target volume
on customClick(x, y)
do shell script "
/usr/bin/python <<END
import sys
import time
from Quartz.CoreGraphics import *
def mouseEvent(type, posx, posy):
theEvent = CGEventCreateMouseEvent(None, type, (posx,posy), kCGMouseButtonLeft)
CGEventPost(kCGHIDEventTap, theEvent)
def mousemove(posx,posy):
mouseEvent(kCGEventMouseMoved, posx,posy);
def mouseclick(posx,posy):
mouseEvent(kCGEventLeftMouseDown, posx,posy);
mouseEvent(kCGEventLeftMouseUp, posx,posy);
ourEvent = CGEventCreate(None);
currentpos=CGEventGetLocation(ourEvent); # Save current mouse position
mouseclick(" & x & "," & y & ");
mousemove(int(currentpos.x),int(currentpos.y)); # Restore mouse position
END"
end customClick
on simpleEncryption(_str)
set x to id of _str
repeat with c in x
set contents of c to c + 100
end repeat
return string id x
end simpleEncryption
on simpleDecryption(_str)
set x to id of _str
repeat with c in x
set contents of c to c - 100
end repeat
return string id x
end simpleDecryption
You just need to change two properties targetVolume and passwordValue. Password can be empty and in that case you can provide it manually. Then just copy this script, paste it to the Script Editor and export via File -> Export -> file format - Application, select Run-only -> Save. You can do the same process for all systems you have, for example Big Sur 1, Big Sur 2, Bootcamp.