• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Make New Temp Script and Script to Open It
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Make New Temp Script and Script to Open It


  • Subject: Make New Temp Script and Script to Open It
  • From: Christopher Stone <email@hidden>
  • Date: Tue, 20 Oct 2015 18:56:49 -0500

Hey Folks,

When I first start scripting an application the first thing I do is create a Temp_Script for that app and a script to open the Temp_Script in Script Debugger.

I've done this by hand for years, but I had to do it about six times in a row recently – got fed up – and wrote a script to do it for me.

A template script is required (I'm using a script bundle).

I'm using the Satimage.osax for strftime, but that's the only dependency and can easily be replicated with AppleScript, ASObjC, or the shell.

I use FastScripts to run almost all of my AppleScripts, and it will create my app-specific folder for me.

So the front folder should be something like this:

~/Library/Scripts/Applications/Finder/

The scripts will be named using the name of the front Finder window, and they will be duplicated to that directory.

It should be easy enough to adapt to the Script Editor app.

(I use the shell in the Open_Temp_Script script, because Script Debugger doesn't always behave properly when scripted directly if the script is already open.  I had a reason for not using the Finder to do it too, but I've forgotten what it was.)

--
Best Regards,
Chris

-------------------------------------------------------------------------------------------
# Auth: Christopher Stone
# dCre: 2015/10/20 03:00
# dMod: 2015/10/20 04:11 
# Appl: Finder & Script Debugger
# Task: Make Temp_Scripts for the given App's open script folder (frontmost in Finder).
# Libs: None
# Osax: None
# Tags: @Applescript, @Make, @Temp, @Script
# Note: Tested only on OSX 10.11.
-------------------------------------------------------------------------------------------
--» PROPERTIES
-------------------------------------------------------------------------------------------
property expandedPathTo : {}
property pathToSpec : {application support, applications folder, desktop, desktop pictures folder, documents folder, downloads folder, favorites folder, Folder Action scripts, fonts, help, home folder, internet plugins, keychain folder, library folder, modem scripts, movies folder, music folder, pictures folder, preferences, printer descriptions, public folder, scripting additions folder, scripts folder, shared documents, shared libraries, sites folder, startup disk, startup items, system folder, system preferences, temporary items, trash, users folder, utilities folder, workflows folder}
-------------------------------------------------------------------------------------------

try

  

  set scriptBundleWithLibs to alias ((path to application support from user domain as text) & "Script_Support:New_File_Here!:Script-Bundle-with-Libraries.scptd:")

  

  tell application "Finder"
    set insertionLocation to insertion location
    set folderName to name of insertionLocation

    

    set newTempScript to duplicate scriptBundleWithLibs to insertionLocation
    set newTempScript to newTempScript as alias
    set name of newTempScript to "Temp_Script ⇢ " & folderName & ".scptd"

    

    set newOpenTempScript to duplicate scriptBundleWithLibs to insertionLocation
    set newOpenTempScript to newOpenTempScript as alias
    set name of newOpenTempScript to "Open ⇢ Script ⇢ 'Temp_Script ⇢ " & folderName & ".scptd'.scptd"

    

  end tell

  

  if expandedPathTo = {} then expandedPathToPaths()
  set scriptPath to makeRelativeAlias(newTempScript)

  

  set openScriptText to "
-------------------------------------------------------------------------------------------
# Auth: Christopher Stone
# Appl: Script Debugger & Shell
# dCre: " & (strftime (get current date) into "%Y/%m/%d %H:%M") & "
# dMod: " & (strftime (get current date) into "%Y/%m/%d %H:%M") & "
# Task: Open the " & folderName & " temp script in Script Debugger.
# Libs: ELb, FLb, GLb, NLb, NLbD
# Osax: None
# Tags: @Applescript, @Script, @Open, @Temp, @Script, @" & folderName & "
-------------------------------------------------------------------------------------------

try

  

  set scriptFile to " & scriptPath & "
  do shell script \"open -a 'Script Debugger' \" & quoted form of scriptFile

  

on error e number n
  stdErr(e, n, true, true) of me
end try

-------------------------------------------------------------------------------------------
"

  

  tell application "Script Debugger"

    

    set newTempScript to open newTempScript
    set bounds of front window to {606, 23, 1920, 1196}
    tell newTempScript to close with saving

    

    set newOpenTempScript to open newOpenTempScript
    set bounds of front window to {606, 23, 1920, 1196}
    tell newOpenTempScript
      set its source text to text 2 thru -1 of openScriptText
      close it with saving
    end tell

    

  end tell

  

on error e number n
  stdErr(e, n, true, true) of me
end try

------------------------------------------------------------------------------------------------
--» HANLDERS
-------------------------------------------------------------------------------------------
on expandedPathToPaths()
  repeat with i in pathToSpec
    set end of expandedPathTo to (path to (get contents of i) from user domain) as text
  end repeat
end expandedPathToPaths
-------------------------------------------------------------------------------------------
on makeRelativeAlias(_item)
  set {oldTIDS, AppleScript's text item delimiters} to {AppleScript's text item delimiters, ":"}
  set _item to _item as text
  # set _item to cng("(\\.scptd):$", "\\1", _item) of me
  set _len to (length of (text items of _item))
  repeat with i from _len to 1 by -1
    set _path to ((text items 1 thru i of _item) as text) & ":"
    if _path is in expandedPathTo then
      repeat with idx from 1 to (length of expandedPathTo)
        if (item idx of expandedPathTo) = _path then
          set refFldr to "path to " & (item idx of pathToSpec) as text
          set diskLocalRef to ("posix path of " & ("(" & "(" & refFldr & " as text) & ") & "\"" & (text items (i + 1) thru -1 of _item) as text) & "\")"
          try
            run script diskLocalRef
          on error
            set refFldr to refFldr & " from user domain"
            set diskLocalRef to ("posix path of " & ("(" & "(" & refFldr & " as text) & ") & "\"" & (text items (i + 1) thru -1 of _item) as text) & "\")"
            try
              run script diskLocalRef
            on error e
              error e
            end try
          end try

          

          set AppleScript's text item delimiters to oldTIDS
          return diskLocalRef

          

        end if
      end repeat
    end if
  end repeat
end makeRelativeAlias
-------------------------------------------------------------------------------------------
on stdErr(e, n, beepFlag, ddFlag)
  set e to e & return & return & "Num: " & n
  if beepFlag = true then
    beep
  end if
  if ddFlag = true then
    tell me
      set dDlg to display dialog e with title "ERROR!" buttons {"Cancel", "Copy", "OK"} default button "OK"
    end tell
    if button returned of dDlg = "Copy" then set the clipboard to e
  else
    return e
  end if
end stdErr
-------------------------------------------------------------------------------------------

 _______________________________________________
Do not post admin requests to the list. They will be ignored.
AppleScript-Users mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
Archives: http://lists.apple.com/archives/applescript-users

This email sent to email@hidden

  • Prev by Date: Re: Countdown Timer
  • Next by Date: Scripting Apple Directory
  • Previous by thread: Re: Countdown Timer
  • Next by thread: Scripting Apple Directory
  • Index(es):
    • Date
    • Thread