Sublime Text Build For Executing Indesign .jsx Scripts on Windows - sublimetext3

I'm trying to write a sublime text build to execute an indesign jsx script strait from sublime text on Windows. For the Mac there's a build by Basil https://github.com/basiljs/basil.js/tree/master/extras/Sublime%20Text that consists of a build and an osascript.
The build is:
// copy this file to ~/Library/Application Support/Sublime Text 2/Packages/User
{
"cmd": ["osascript", "$packages/Basiljs/run_idscript_6.0.scpt", "$file"]
}
The osascript is:
--usage:
--osascript run.scpt myscript.jsx
on run argv
set aScriptPath to "#include \"" & item 1 of argv & "\""
tell application "Adobe InDesign CS6"
do script aScriptPath language javascript
end tell
end run
I would like to do this with For Windows for my build I have done
{
"cmd": ["wscript", "$packages/creative-scripts/run_indesign.vbs", "$file"]
}
and for my wscript I have done
myScript = Wscript.Arguments.Item(0)
Set myInDesign = CreateObject("InDesign.Application")
MsgBox myScript ' just to check the path
Set myFileSystemObject = CreateObject("Scripting.FileSystemObject")
Set myFile = myFileSystemObject.GetFile(myScript)
myInDesign.DoScript myFile, 1246973031
I was getting the following error message
Error: Object required: 'idScriptLanguage'
Code: 800A01A8
I have now edited the script putting in the change as per Vlad's answer and it work very well now.
Trevor

Replacing the idScriptLanguage.idJavascript with it's actual value (1246973031) will solve the problem.

I have come up with a solution with this sublime build :-)
{
// for script to run must have #target "InDesign-7.0" "InDesign" Ietc. in it :-( otherwise the script will just open in the estk
"cmd": ["C:\\Program Files (x86)\\Adobe\\Adobe ExtendScript Toolkit CC\\ExtendScript Toolkit.exe", "-run", "$file"]
}
Above is for a 64 bit system just remove the " (x86)" for a 32 bit one
Take note of the need for the #target
It will come up with a standard warning "Do you about to run .... Do you wish to run the script?"
So one needs to press y space or enter. Not too big a deal, but to suppress this one can put the script into the "Adobe Scripts" folder in Document then the warning won't come up.
See https://forums.adobe.com/message/4689581 and http://jfli04.blogspot.co.il/2011/08/how-to-run-js-in-estk-with-command-line.htm

Related

Applescript if no file is added

I have the following automator apple script that I'm using so that when I drag a file into a dock icon, it opens that file in vim:
on run {input, parameters}
set filename to POSIX path of input
set cmd to "clear && 'vim' '" & filename & "' && exit"
tell application "iTerm"
set newWindow to (create window with default profile)
tell current session of newWindow
write text cmd
end tell
end tell
end run
However, I would also like to allow clicking the icon itself to open vim without any file, i.e., running $ vim. How would I change the above script so that:
If a filename is passed, I open vim with that file, vim filename
If no filename is passed (the icon is just double-clicked), it just opens vim, with vim ?
The following example AppleScript code will do as you've asked; however, keep in mind that input is a list and as presently coded it is expecting a single item list, meaning you've only dragged and dropped one file onto the app's Dock Tile:
on run {input, parameters}
if not input is equal to {} then
set filename to POSIX path of first item of input
set cmd to "clear && 'vim' '" & filename & "' && exit"
else
set cmd to "clear && 'vim' '" & "' && exit"
end if
tell application "iTerm"
set newWindow to (create window with default profile)
tell current session of newWindow
write text cmd
end tell
end tell
end run
Note: The example AppleScript code is just that and does not contain any error handling as may be appropriate. The onus is upon the user to add any error handling as may be appropriate, needed or wanted. Have a look at the try statement and error statement in the AppleScript Language Guide. See also, Working with Errors. Additionally, the use of the delay command may be necessary between events where appropriate, e.g. delay 0.5, with the value of the delay set appropriately.

How to remove dead files from Open Recent list in Sublime Text 3?

In Sublime Text 3 if I go to:
MENU: File>Open Recent
There are files in that list which are no longer available.
How can I clean that list of dead files?
I don't want to clear the full list, just the dead ones.
Note: I've followed How to increase number of recent files in Sublime Text 3? to get 30 recent files showing in this menu.
Following this post over on the Sublime Forum it can be done by editing the Session.sublime_session file.
For example: I'd edited etc/hosts so I could block myself from watching youtube, but with it being in the recent files list in Sublime it's easy to unblock myself thus I wanted to remove /etc/hosts from my recent file list in Sublime (ST3).
My copy of Sessions.sublime_session is in ~/.config/sublime-text-3/Local/ from which I deleted all lines containing etc/hosts.
The only caveat is that you can't edit that file using Sublime, Sublime should not be running, I used a different text editor.
Final caveat this is the solution for linux, and ST3, for windows and mac I'm guessing there's something similar.
I found out how to do this using this python script here:
https://github.com/STealthy-and-haSTy/SublimeScraps/tree/master/session_cleaner
I don't want to post the python code as I don't have permission to do so but that has been up on GitHub for a couple of years so there should be no worries of it disappearing anytime soon.
I've written a batch file that will start the python file, see the code below. Just name it RunSessionCleaner.cmd and place this in the same folder as the sublime_session_clean.py file.
#echo off & title %~nx0 & color 5F & chcp 65001 >NUL
rem Based on this thread here: https://stackoverflow.com/a/13351373
goto :MY_ROUTINE
:CMD_SIZE
chcp 850 >NUL & set "uiWidth=%1" & set "uiHeight=%2"
mode %uiWidth%,%uiHeight%
if %4==TRUE (set /a "uiHeightBuffer=uiHeight+%3")
if %4==TRUE (powershell.exe -ExecutionPolicy Bypass -Command ^
"&{$H=get-host;$W=$H.ui.rawui;$B=$W.buffersize;$B.width=%uiWidth%;$B.height=%uiHeightBuffer%;$W.buffersize=$B}")
if %4==FALSE (powershell.exe -ExecutionPolicy Bypass -Command ^
"&{$H=get-host;$W=$H.ui.rawui;$B=$W.buffersize;$B.width=%uiWidth%;$B.height=%uiHeight%;$W.buffersize=$B}")
chcp 65001 >NUL & goto :EOF
:MY_ROUTINE
call :CMD_SIZE 60 7 222 TRUE
title Cleaning folders, files and projects...
echo Cleaning folders, files and projects...
:: Full path to data folder W:\Apps (Portable)\Sublime Text\Data
:: Full path to python.exe W:\Apps (Portable)\Sublime Text\Data\Packages\User\SessionCleaner\python\python.exe
:: Full path to sublime_session_clean.py W:\Apps (Portable)\Sublime Text\Data\Packages\User\SessionCleaner\sublime_session_clean.py
:: Or like I have done use a relative directory to the Data folder
:: The SsssionClearner.py file is located in: W:\Apps (Portable)\Sublime Text\Data\Packages\User\SessionCleaner
::
:: Change this line below to suit your needs.
".\python\python.exe" "sublime_session_clean.py" --data-dir "..\..\..\..\Data" --workspaces --files --folders
echo/
goto :EXIT_ROUTINE
:EXIT_ROUTINE
rem call :CMD_SIZE 100 10 222 FALSE
title Exiting routine...
echo Exiting routine...
set /p "=" <NUL &
ping localhost -n 3 >NUL & exit
exit
Change line 24 of the code above to suit your paths. You can just use relative paths here like I have done so you can do that too.
This batch file can be clicked on or set up in Task Scheduler to start up when the PC does to clean out all the non-existent files or workspaces.
Please note, Sublime Text needs to be closed in order for this to work.

Searching in Finder from Selection

Usually I get an excel spreadsheet with dozens of filenames, for which I then need to go and search individually.
Spreadhseet
Is there a way that I could simply:
Select All filenames in e.g. row A of Excel,
then Search for all these files on "This Mac"
then Copy all found files into the New Folder on the Desktop
So far I've tried the first part of searching and this is what i get :a)
Automator with Variable. But the problem is, it only searches for 1 file from selection
b)
Automator with Shell Script (Copy to Clipboard > Open Finder > CMD+F (to highlight Search dialog) > CMD+V). It opens a new Finder window, but it doesn't paste the clipboard into search dialog
c) /usr/bin/pbcopy
on run {input, parameters}
tell application "System Events"
keystroke "f" using {command down}
keystroke "v" using {command down}
end tell
return input
end run`
End result, is same as option b). I was planning to run this in Automator as a 'Service', which I could later assign to Keyboard Shortcut.
I am pretty sure there should be a simple shell option for this - any advice would be much appreciated.
I made a bash script that does what you want. You would basically select a bunch of filenames in Excel, or any other app, and copy them to the clipboard with ⌘C. After that you need to run the script and it will take items from the clipboard and search for TIFF or JPEG images that match that name and copy them to a directory on your Desktop called Selected Files:
#!/bin/bash
# Get contents of clipboard into bash array
files=( $(pbpaste) )
# Create output directory - no checks for already existing or already containing files
OUTDIR="$HOME/Desktop/Selected Files"
mkdir -p "$OUTDIR"
# Iterate through fetching files
for ((i=0;i<${#files[#]};i++)) ; do
name=${files[i]}
result=$( mdfind "kMDItemDisplayName == \"${name}.*\" && (kMDItemKind==\"TIFF image\" || kMDItemKind==\"JPEG image\")" )
if [ -f "$result" ]; then
echo $name: $result
cp "$result" "$OUTDIR"
else
echo ERROR: Searched for: $name, found $result
fi
done
I am not sure of your level of familiarity with bash, so you may be able to ignore the following...
Make a new directory for your own scripts:
mkdir -p $HOME/scripts
Save the above script in that directory with filename:
$HOME/scripts/gather
Make the script executable by typing this into Terminal:
chmod +x $HOME/scripts/gather
Edit your login profile ($HOME/.profile) and add your $HOME/scripts directory to your PATH:
export PATH="$PATH":$HOME/scripts
Then start a new Terminal and you can use any script that you have saved in $HOME/scripts without needing to specify the full path to it, e.g.:
gather
Following information kindly contributed by #user3439894 in comments section, as I am out of my depth on this aspect...
To use a keyboard shortcut, you'd have to create an Automator "Service workflow" with a "Run Shell Script" action, which you can assign a keyboard shortcut to under: System Preferences > Keyboard > Shortcuts > Services

String captured from window text invalid as pathname (AutoIT)

I am running into a problem automating an installation procedure. I want to install a program, and then patch it with a custom UserPatch to remove some glitches.
The UserPatch executable must be run from the installation directory, so I must retrieve this address from the installer. Then, after the program is installed, the script must copy the UserPatch file to the installation directory, and run it from there.
I retrieve the pathname as shown below. The script copies the raw text from the window, which I strip down to just the line containing the pathname.
WinActivate("Dir browse box title")
$InstallDir = WinGetText("Dir browse box title")
$split = StringSplit( $InstallDir, "&Path", 1)
$InstallDir = $split[2]
$split = StringSplit( $InstallDir, "&OK", 1)
$InstallDir = $split[1]
ControlClick("Dir browse box title", "&Drives", "[Class:CButtonClassName; INSTANCE:2]")
Sleep(100)
When printing "$InstallDir" after the above procedure, it shows exactly what I want it to be: "C:\Program Files (x86)\Path to\Installation folder" (without '"').
The problem is this: It doesn't copy the file when I run the code snippet below. It does work when I hardcode the pathname (commented in the code below), but not when using the $InstallDir variable as retrieved by the code snippet above.
; Install the UserPatch
; $InstallDir = "C:\Program Files (x86)\Path to\Installation folder"
$UserPatchName = "SetupAoC.exe"
FileCopy($UserPatchName, $InstallDir & "\" & $UserPatchName)
Run($InstallDir & "\" & $UserPatchName)
WinWait("SetupAoC - Feature Update Tool")
ControlClick("SetupAoC - Feature Update Tool", "Install", "[Class:DirectUIHWND; INSTANCE:1]")
Send("{SPACE}")
Sleep(2000)
WinClose ("SetupAoC - Install Complete")
WinClose ("SetupAoC - Feature Update Tool")
I've got the feeling that I'm missing something obvious, but I really can't tell what the problem is? Any ideas?
Thanks in advance!
EDIT in reply to comments:
After
$InstallDir = WinGetText("Dir browse box title")
the value of $InstallDir is
&Drives
C:\ Crucial M500
&Folders
&Path
C:\Program Files (x86)\Path to\Installation folder
&OK
&Cancel
I then use StringSplit, which creates an array of strings, separated by the specified delimiter.
OK, problem eliminated.
The problem was that my "C:\path...." string was preceded and trailed by two #CRLF characters (new lines). These were also present in the raw data that I copied from the window, as I didn't include them in my delimiters.
I didn't notice them when printing the output, as they're white-space. I found out when writing the $InstallDir variable to a file, in a desperate attempt.
Anyway, Solved with
$InstallDir = StringReplace($InstallDir, #CRLF, "")
Thanks for the tips, #Matrix and #McBarby!

How do I write to a text file using AppleScript?

So, that's it. How can I write to a text file using AppleScript?
I've tried googling around, but answers seem to be years old and I'm not really sure what should be the preferred idiom this days.
on write_to_file(this_data, target_file, append_data) -- (string, file path as string, boolean)
try
set the target_file to the target_file as text
set the open_target_file to ¬
open for access file target_file with write permission
if append_data is false then ¬
set eof of the open_target_file to 0
write this_data to the open_target_file starting at eof
close access the open_target_file
return true
on error
try
close access file target_file
end try
return false
end try
end write_to_file
Interfacing with it can be cleaned up with the following...
my WriteLog("Once upon a time in Silicon Valley...")
on WriteLog(the_text)
set this_story to the_text
set this_file to (((path to desktop folder) as text) & "MY STORY")
my write_to_file(this_story, this_file, true)
end WriteLog
A short version in pure AppleScript:
set myFile to open for access (choose file name) with write permission
write "hello world" to myFile
close access myFile
It seems there is no native one command solution. Instead you have to open and later close the file.
#JuanANavarro.
When using the shell you should use quoted form of for the TEXT and the file path.
This will help stop errors with spaces in file names and characters like apostrophes in the text for example.
set someText to "I've also learned that a quick hack, if one only wants to spit a bit of text to a file, is to use the shell."
set textFile to "/Users/USERNAME/Desktop/foo.txt"
do shell script "echo " & quoted form of someText & " > " & quoted form of textFile
The above script works fine.
If I did not have & quoted form of someText
but instead I had & someText I would get the following error.
error "sh: -c: line 0: unexpected EOF while looking for matching `''
sh: -c: line 1: syntax error: unexpected end of file" number 2
The apostrophes in "I've" is seen as part of the command.
If I had
set textFile to "/Users/USERNAME/Desktop/some foo.txt" as my file path ( note the space.) And did not have & quoted form of textFile but instead I had & textFile
Then when the file was written out it would write to a file named "some" and not "some foo.txt"
I've also learned that a quick hack, if one only wants to spit a bit of text to a file, is to use the shell.
do shell script "echo TEXT > some_file.txt"
For me running do shell script was too slow on a PowerBook G4 when executed in a loop 300000 times ;), but of course that's quicker to write which sometimes makes sense. You would also want to escape shell characters like this:
do shell script "echo " & quoted form of foobar & " >> some_file.txt"
and for aesthetic reasons I would use
tell me to do shell script "#..."
but I haven't verified yet (what I believe) that if "do shell script" is in a block of "tell Finder" for example it is Finder process that creates a subshell. With "tell me to do shell script" at least Script Editor log looks better for me. ;)

Resources