Another script library question

I had a quesiotn about this and "kel" gave me this suggestion:
put these in [external script file]:
property var1 : "VAR1"
property var22 : "VAR22"
property var333 : "VAR333"
then in the actual script, do:
set f to [external script file]
set s_lib to load script f
var22 of s_lib
This works but there is a problem. I have now hundreds of lines of code with almost 30 variables, occurring dozens of times in the text and to manually find each and every one of them and paste "of s_lib" after them would be just awful.
So my question is: is there a way to avoid it and simply "#include" the library somehow, like in C++?
  Mac OS X (10.4.8)  

Hello Asu,
I'm afraid you've missed an important point on global declaration.
The point is that the variables imported by the previous 'SCRIPT 2' become global variables in the importer script just as though they were declared as global in importer's implicit run handler. And in order to refer to those global variables from a handler other than implicit or explicit run handler, you have to declare them as global in the handler unless you have declared them as global in the top level of importer script. In this respect, the global declaration in 'handler1()' in 'SCRIPT 2' is mandatory.
Global variable declared in top level of a script and global variable declared in a handler in a script have different behaviours in regards to their scope. Please peruse the language manual for details:
cf. pp. 311-323
'Scope of Script Variables and Properties'
AppleScriptLanguageGuide.pdf
By the way, of course you may define a new variable and set it to an imported global variable, but then I think you should lose the only advantage of 'SCRIPT 2' over 'SCRIPT 1', that is no reassignments of variables are needed in 'SCRIPT 2'.
As for handlers in external script, you'd need more complicated device. See the codes below. 'SCRIPT 1A' and 'SCRIPT 2A' are revised samples for 'SCRIPT 1' and 'SCRIPT 2' respectively. Although I'm posting them here, I don't recommend this sort of coding practice at all. It unnecessarily complicates matters and makes debugging harder. I'd recommend instead the simple and natural approach in AppleScript, that is; to load an external script and to tell it to do its tasks (as kel has explained), that should minimize non-essential dependencies and maxmize modularity (in AppleScript's own fashion).
Hope this helps,
H
PS. 'run' command of AppleScript and 'run script' command in Standard Additions are utterly two things. The latter creates a new instance of script every time it is invoked and hence cannot share the context with caller script in normal means. And I see no reason to use 'run script' where I can use 'run'.
-- SCRIPT 1A
(* Import properties *)
property p1 : {} -- required if it is used in external handler with 'my' possessive. -- [*A]
property p2 : {} -- idem. -- [*A]
property pf1 : {} -- mandatory. -- [*A]
property pf11 : {} -- mandatory. -- [*A]
main()
on main()
set o to load script file "RAM Disk:test:properties.scpt" -- load external script
set {p1, p2, pf1, pf11} to o's {p1, p2, pf1, pf11}
return {p1, p2, pf1(), pf11(), handler1()}
end main
on handler1()
return {pf1(), pf11()}
end handler1
  [A] Alternatively, these properties can be declared as globals as well.
   The point is that they must not be local.
   (Also if the following code were entirely in implicit or explicit run handler,
   no declaration of properties or globals should be required, for they become implicit globals)
-- external script "properties.scpt" contains following code
on f1() -- [*1]
--return f11() -- [*2]
return pf11() -- [*3]
end f1
on f11() -- [*1]
return (my p1) + (my p2) -- [*4]
end f11
property p1 : 1
property p2 : 2
property pf1 : f1
property pf11 : f11
  [1] Handler definitions must precede the definitions of the handler name's properties.
    e.g. f1()'s definition must precede the definition of 'property pf1 : f1'.
  [2] This should fail if f1() is called (via pf1()) in a script that loads this script; e.g.
    -- code of caller
    set o to load script file "path to this script"
    set pf1 to o's pf1
    return pf1() -- this should throw error -1708
    -- end of code of caller
  [3] Always invoke other handler by its 'global' (i.e. 'property') name. cf. [2]
  [4] Possessive 'my' is required to resolve property variable properly in a handler that is
   assigned to a property by itself.
    e.g. 'my p1' is required in 'f11()' when 'p1' is a property and 'f11()' is assigned to a property.
-- end of "properties.scpt"
-- END OF SCRIPT 1A
-- SCRIPT 2A
(* Import globals *)
main()
on main()
set o to load script file "RAM Disk:test:globals.scpt" -- load external script
tell o to run
global g1, g2 -- mandatory -- [*A]
--global gf1, gf11 -- [*B]
return {{g1, g2, gf1(), gf11()}, handler1()}
end main
on handler1()
global g1, g2 -- mandatory -- [*C]
--global gf1, gf11 -- [*B]
{g1, g2, gf1(), gf11()}
end handler1
  [A] If the code currently in main() were in implicit or explicit run handler instead,
   no global declaration should be required, for the variables become implicit globals.
  [ B] Not required for 'global' handler name (that are redefined as global in 'globals.scpt').
  [C] Always required in a handler other than implicit or explicit run handler.
-- external script "globals.scpt" contains following code
global g1, g2 -- mandatory.
main()
on main()
global gf1, gf11 -- mandatory -- [*1]
set g1 to 1
set g2 to 2
set gf1 to my f1 -- [*2]
set gf11 to my f11 -- [*2]
end main
on f1()
--return f11() -- [*3]
return gf11() -- [*4]
end f1
on f11()
return g1 + g2
end f11
  [1] If the code currently in main() were in implicit or explicit run handler instead,
   no global declaration should be required for handler names, for the variables become implicit globals.
  [2] Possessive 'my' is required to resolve handler name properly in another handler.
   If the code currently in main() were in top level of script (i.e. in implicit run handler) instead,
   'my' possessive should not be required.
  [3] This should fail if f1() is called (via gf1()) in a script that loads this script; e.g.
    -- code of caller
    tell (load script file "path to this script") to run
    return gf1() -- this should throw error -1708
    -- end of code of caller
  [4] Always invoke other handler by its 'global' name. cf. [3]
-- end of "globals.scpt"
-- END OF SCRIPT 2A
  Mac OS 9.1.x  

Similar Messages

  • The ipod is synced with another itunes library

    "the ipod is synced with another itunes library" and they gave me two choices...
    1. to delete all my ipod data.
    2. cancel..
    Guys before you reply please please read why i have turned to the support/community as this is my last resort before you reply with the most general answers which i would have already tried and did not work.
    Ok, so my old computer died on me a month ago and i had not backed up my ipod touch for a few months already.. so when my com died on me i was with quite an outdated OS. when i got my com back a few days ago, i straight away told myself to backup my ipod touch, so i did. when i synced with this new itunes and clicked cancel for "the ipod is synced with another itunes library" question. it loaded like a normal syncing would do. i left it alone..
    a few mins later i checked my itunes and noticed the word "DELETING ------" and i'm like WTH!?! and straight away unplugged the cable. nearly 80% of my games were deleted! all save data and stuffs gone.. i dont know what happened so i searched online.
    to cut it short i found out about authorizing accounts so i deauthorized "all itunes" things and authorized this current one..
    it still shows me "the ipod is synced with another itunes library" and it tried to delete my games despite that.
    someone help me please. i have like 3 games left that still has my high scores from my 50+ games i had previously.
    oh and one more this. i have never jailbroked my itouch before and all games are legit-ly downloaded so thats about it. anything else you need to know please feel free to ask!
    I sincerely thank you for helping me.

    I would move the backups to a safe place and let iTunes erase and restore the iPods.  Then move the other backup to the correct location and then restore from the old backups.  It may not work but you are no worse off.  The backups are located here:
    iTunes places the backup files in the following places:
    Mac: ~/Library/Application Support/MobileSync/Backup/
    Windows XP: \Documents and Settings\(username)\Application Data\Apple Computer\MobileSync\Backup\
    Windows Vista and Windows 7: \Users\(username)\AppData\Roaming\Apple Computer\MobileSync\Backup\
    Note: If you do not see the AppData or Application Data folders, you may need to show hidden files (Windows XP,  Windows Vista and Windows 7), or iTunes may not be installed in the default location. Show hidden files and then search the hard drive for the Backup directory.

  • Question about using script library

    Dear Mavens,
    I am writing a script that has lots of predefined text items because it deals with reprocessing certain javascript files.
    Here is an example from the beginning of the script (with the actual javascript code mangled because it seems to mess up the display):
    set sdinTXTcf_imgsrc to "<i_mg src=dfaasfaf"<P>
    set sdinTXTcf_onload to " onLoad="p_arent.frames[1].readystate(sfsafasfads"
    set sdinTXTcf_inBetween to "</d_iv>');
    } else {
    parent.frames[0].document.write('<div align="c_enter"><img src=\""
    this section is now getting quite long and I thought of putting it into an external file. What I was hoping to do is to load all these "set this to that" commands into my script then use them as if they had been defined in it.
    The following is a toy script to demonstrate my problem.
    I wrote a mini library which ilooks thusly:
    set var1 to "VAR1"
    set var22 to "VAR22"
    set var333 to "VAR333"
    Then a mini script that calls the mini library:
    load script file "whatever:toylib.scpt"
    get var1
    The result is
    tell current application
    load script file "whatever:toyscript.scpt"
    set var1 to "VAR1"
    set var22 to "VAR22"
    set var333 to "VAR333"
    "The variable var1 is not defined."
    setting up var1 as global does not help either, either in the scrip or in the library
    Now, I can set up the mini library script as a subroutine to be called, such as
    on toy()
    set var1 to "VAR1"
    set var22 to "VAR22"
    set var333 to "VAR333"
    return {v1:var1, v22:var22, v333:var333}
    end toy
    and in the main scipt I can do a
    set loaded to load script file "whatever:toylib.scpt"
    tell loaded
    set var1 to v1 of toy()
    end tell
    get var1
    which works but it is actually more cumbersome than simply having to scroll down dozens of lines of code on the top of the script.
    I'm sure I'm missing somethig here, your help will be appreaciated
      Mac OS X (10.4.8)  

    Hi Asu,
    There are several ways to do this. The easiest is to
    use properties. Your script library might look like
    this:
    property var1 : "VAR1"
    property var22 : "VAR22"
    property var333 : "VAR333"
    You might load it and get values like this as an
    example:
    set f to choose file -- the script to load
    set s_lib to load script f
    var22 of s_lib
    Note that this is not the only syntax.
    When you do things like 'set' in the script library,
    you need to run the loaded script or subroutines
    within it.
    gl,
    It worked. THANKS!

  • My iPod is synced with another iTunes library?!?!

    We got a new computer a couple of months ago and I'm trying to download more tunes from iTunes. It's saying my iPod is synced with another iTunes library. It's asking if I want to erase this iPod and sync with this iTunes library. NO! I don't want to lose all of my songs! I just want to add the new ones! We don't have our old computer anymore so I can't access the old library. Am I screwed at this point?
    Thanks for any help!!!

    Copying from iPod to Computer threads...
    http://discussions.apple.com/thread.jspa?threadID=776996&tstart=0
    http://discussions.apple.com/thread.jspa?threadID=805256&tstart=0
    http://discussions.apple.com/thread.jspa?messageID=797432&#797432
    http://discussions.apple.com/thread.jspa?threadID=809624&tstart=0
    Also these useful internet articles...
    http://www.engadget.com/2004/11/02/how-to-get-music-off-your-ipod/
    http://playlistmag.com/help/2005/01/2waystreet/
    iPod: Frequently Asked Questions
    http://docs.info.apple.com/article.html?artnum=60920
    Patrick

  • Ipod is synced with another itunes library"erase and sync"!!

    im trying to convert all my music on a different computer on a new itune but this message comes up (the ipod is synced with another itunes library. an ipod can be synced with only one itunes library at a time) "erase and sync replaces the contents of this ipod with contents of this itunes library". i need to find out if i do a "erase and sync" will my music library from my ipod be automatically deleted and replaced with and empty itunes library ???

    Yes it will be erased and the empty library will replace it. So first thing is you want to say NO to that question. For information/help on getting the stuff into your new computer...
    How to use your iPod to move your music to a new computer using iTunes7
    http://docs.info.apple.com/article.html?artnum=300173
    How to use your iPod to move your music to a new computer using iTunes6
    http://docs.info.apple.com/article.html?artnum=304304
    Copying from iPod to Computer threads...
    http://discussions.apple.com/thread.jspa?threadID=776996&tstart=0
    http://discussions.apple.com/thread.jspa?threadID=805256&tstart=0
    http://discussions.apple.com/thread.jspa?messageID=797432&#797432
    http://discussions.apple.com/thread.jspa?threadID=809624&tstart=0
    Also these useful internet articles...
    http://www.engadget.com/2004/11/02/how-to-get-music-off-your-ipod/
    http://playlistmag.com/help/2005/01/2waystreet/
    iPod: Frequently Asked Questions
    http://docs.info.apple.com/article.html?artnum=60920
    Patrick

  • An ever-ubituous import library question ???

    So here's my dillemma:
    My desktop computer is slooooooooo. My laptop is fast.
    My large (over 100 gig) library is on my desktop computer -- well, really it's on an external hard drive, but the itunes I use is on the desktop.
    If I import the library from the harddrive into my laptop computer, will I see EVERYTHING as if it's from the desktop (playlists, play count, ratings, etc)?? Thanks so much

    Directly messing with the XML and ITL files is always a nightmare, isn't it?
    Here's my solution:
    First, download this: http://otto.homedns.org/itunes/SaveRatings.zip
    Open iTunes on the library you want to save the information for. Then double click the SaveRatings.HTA to run it. Click the "Save Ratings" button.
    What this does: It will read the iTunes Library, and save the ratings, playcount, and last played time for all the tracks that actually have that info. This information will be saved into a file called "ratings.xml".
    Now, copy your music over to another computer and import it all into another iTunes library. Yeah, the playcount and such are gone. Bummer. So now you copy over the SaveRatings.hta and the ratings.xml file you made. Run the HTA again. This time, click "Restore Ratings". It'll put all the information back into iTunes.
    Why this? Because it's not limited by such things as "location". It's matching on three things: Album, Artist, Song Title. If those match, it considers it a match, and sets the information accordingly.
    If you use a little bit of thought, this will let you combine a couple of sets of music and restore the relevant info in iTunes, without worrying about drive letters or copying weird ITL files or any of that wacky stuff.
    A few caveats:
    -This script is slow. It takes a long time to run through your iTunes library, and there's no progress indicator. Be patient, when it's done, the script screen will change.
    -This script isn't perfect. A few tracks will not be found in the Restore process. There's always a few... So when it can't find a track, it'll spit that fact out onto the screen after the Restore finishes. Than you can find that track yourself and set your own rating and such.
    Enjoy.

  • 2nd iPod is stating "This iTunes is in use by another iTunes Library.......

    When I plugged my iPod in, no music was in the iTunes Library. I looked on the hard drive (I think) & looked in all files & didn't find ANY music that I purchased or downloaded myself. When I plug in my mom's iPod, none of the music on her iPod displays whats on there & a message pops up: "This iTunes library is being occupied by another iTunes library, do you want to transfer..." PLEASE Help! I have emailed 4 times & no help. Thanks for understanding.

    OK, first do some reading on your new toys.
    How to use multiple iPods with one computer
    http://docs.info.apple.com/article.html?artnum=300432
    Let us know if you have any questions after that, and we will need to know how many XP user accounts you are using.

  • Exporting a TV Series to another iTunes library - keeping all tag info?

    Hi
    I have a TV series that I ripped from my DVDs into iTunes.
    There are 3 seasons. All artwork, episode numbers, and seasons are grouped nicely and appear in iTunes exactly how they should.
    MY QUESTION IS: Does anyone know how to export and import this nicely grouped TV series to another iTunes library on another PC (i.e. from mine to my sisters library) without loosing all metadata/tags etc.
    I did this a while ago with another TV series, but I remember that the movie files are automatically imported into the Movies section of iTunes.
    I had to painfully go through all the episodes and seasons and re-group them all again and change them to the TV programmes section - took a good hour and half - do not want to do that again!
    Any ideas would be greatful...

    Hi,
    All file formats are .m4v (mp4) which work fine with iTunes which does support tags and when I have imported to another PC, it still defaults to the Movie section, so the 'TV Show' tag doesn't seem to make a difference.
    My only problem is that the meta tags (I'm guessing) are stored within the master iTunes Library.xml file and not the movie files them selves, hence the reason why all movie files default to the movie section.
    I thought of creating a Playlist and adding all the seasons of the TV series, exporting that (to XML), then re-importing to other PC.
    Of course, the only problem is file paths in the XML point to the real location of the mp4 on my PC, not on the PC I want to export to - meh.
    Anyone else have any ideas?

  • Im stuck on trying to call another script

    I have a script that I want to excute another script that places phone calls. I have both scripts done but my main script is not excuting my phone call script. From what I have read on the forum the highlighted line is what i think is what im supposed to do but it does not seem to be working. Sorry if this is a dumb question I am new at UCCX scripting.

    Matt, I don't see what you are talking about when you say "the highlighted line."
    Also, you didn't mention how your calling the second script from the first one.  I wonder if you meant to upload a screenshot?
    Anthony Holloway
    Please use the star ratings to help drive great content to the top of searches.

  • HT1386 i downloaded the new version of itunes. when i plug my phone into the computer to connect its saying my device is synced with another itunes library. how do i get my old itunes back? or how can i get my old itunes stuff to the new one?

    I downloaded the new version of itunes and when i plug my phone into the computer and try and do something in itunes it wont let me because my device is synced to another itunes library. how do i get my old itunes back? or how can i sync my stuff into the new itunes with out deleting anything off my phone? HELP

    Copy the iTunes folder from the old computer to your new one.

  • Since reinstalling itunes i can no longer sync. Error message says already synced with another itunes library. I get a blank sync - no songs, photos ect as it comes up with this error whenever try to select what is to be synced. Help - lost everything

    Since reinstalling itunes i can no longer sync. Error message says already synced with another itunes library. I get a blank sync - no songs, photos ect as it comes up with this error whenever try to select what is to be synced. Help - lost everything. Complete nightmare - Apple sort a fix NOW, but will take any help

    Plawexki wrote:
    ...  do you know if the contacts, photos, messages etc will be wiped?
    Yes... Everything will be Wiped and Replaced with what is currently on Your Mac.
    SYNCING with iTunes
    See here  >  http://support.apple.com/kb/HT1386
    From Here  >  http://www.apple.com/support/iphone/syncing/
    You may find this information of interest...
    Have a read here...
    https://discussions.apple.com/message/18409815?ac_cid=ha
    And See Here...
    How to Use Multiple iDevices with One Computer

  • My ipod says it was et up with another itunes library, it wasn't, and when I add songs to my library when I go back into it they are all gone, please help im going in circles

    Please help, I am constanly re importing songs, I have to re sync my ipod to my library each time i plug it in, and I am unable to import songs from my media player, any ideas?

    When I plug it in I get the **'s ipod is already synced with another itunes library so do I want to erase & sync message
    Even though it is the same music in iTunes, iTunes does not see it as the exact same library because you had to re-add all the songs to it.
    You will need to erase and sync and you iPod will simply end up as it is now.
    It's like of your house burns down and you rebuild it exactly the same, it is still not the "same" house it was.

  • Trying to sync iPod with library, but receive this message, "The iPod is synced with another itunes library.  Do you want to erase this ipod and sync with this itunes library".  I do not want to erase my iPod... Any suggestions??  Please help!!

    Trying to sync ipod with itunes library, but I keep getting this message, "  The ipod is synced with another itunes library.  Do you want to erase this ipod and sync with this i tunes library?" 
    I do not want to erase my ipod!!!  Any suggestions?? please help!

    Another way. You can use a USB flash drive & the camera connection kit.
    Plug the USB flash drive (works the same with an SD card) into your computer & create a new folder titled DCIM. Then put your movie/photo files into the folder. The files must have a filename with exactly 8 characters long (no spaces) plus the file extension (i.e., my-movie.mov; DSCN0164.jpg).
    Now plug the flash drive into the iPad using the camera connection kit. Open the Photos app, the movie/photo files should appear & you can import. (You can not export using the camera connection kit.)
    Using The iPad Camera Connection Kit
    http://support.apple.com/kb/HT4101
     Cheers, Tom

  • Why does it tell me my ipad is synched with another itunes library and wants to erase the thing when I want to synch it?  I haven't synched it with any other mac but my own.

    why does it tell me my ipad is synched with another itunes library and wants to erase the thing when I want to synch it?  I haven't synched it with any other mac but my own.

    Hi Lisa,
    I know from experience that this must be a frustrating situation for you especially if you don't want to loose the music/video content that is currently on your ipod. Unfortunately though you may have to consider re-syncing it as it thinks its currently synced with another computer.
    If you bought any music that is on the ipod through itunes you can opt to right click the ipod in itunes and 'transfer purchases' if you authorise your library in the 'Store' menu in itunes. Some reasons for this happening may include some of the following:
    Deleting and reinstalling your itunes on the computer.
    Removing the account you had on the computer you used itunes in and making a new one. (User account, eg: Lisa).
    Changing computers in the past.
    A friend or family member syncing it on their computer to give you there music.
    A sign of a failing iPod.
    Alternatively you can opt to not sync it and keep the music that is on your ipod there but this means you will never be able to update your ipod.
    Hope this helps!

  • I have replaced my laptop and installed iTunes. When I try to sync my iPad or iPhone it says they are already linked to another iTunes library. How do I get back to my original library.

    I have replaced my laptop and installed iTunes. When iffy to sync my iPad or iPhone it says they are already linked to another iTunes library and will only let me transfer purchased items. How do I get back to my original library.

    Check out the solution found here.
    If you do a restore you will lose everything.  Some things will be backed up in iCloud but not everything.

Maybe you are looking for

  • Ipod not being recognized by the emac

    My 20 GB photo/color ipod was not working, so it was suggested that the ipod get a new hard drive. After installing the new hard drive the ipod will not turn on and keeps returning to disk mode. When I plug it into the computer, it is still not showi

  • How can my replacement gain access to all the files on my work computer

    I am retiring from my place of employment after 14 years on the job--my choice as I've reached retirement age.  I've been a Mac guy for over 5 years now and my replacment is inheriting my computer, a Mac Pro with a 2TB hard drive I added a couple of

  • How can I transmit video from my Imac to my TV?

    How can I connect my Imac to my television to view movies downloaded on the net?  The back of the Imac does not have the small port that is on my MacBook to attach the adapter.

  • Message processing failed in XML parser

    This is IDoc to file integration. When I test (WE19), I did not put any value in the 'Quantity' field (which is 6 characters long).In the message mapping I put a condition to see if the value is empty then put zero, and it did not give any error. I h

  • N-Gage QD Fireware Help

    My N-Gage QD Version i'm in USA. V 4.00 11-06-2004 RH-47 I Heared there was an upgrade for my phone model. I called up N-Gage.com support and they told me they will only upgrade if there a problem with Phone. Sence the N-Gage QD being a Gaming Phone