Thursday, March 30, 2017

#1 2017-03-14 09:51:11 am

snaplash
Member
Registered: 2014-08-21
Posts: 41

Best way to pass Variable?

Hi All,

I am uploading to Youtube Automatically using youtube-upload (https://github.com/tokland/youtube-upload) as below:

Applescript:

on run {theRecord}
   
   do shell script "source ~/.bashrc && /usr/local/bin/youtube-upload --title=" & quote & listingStreetNumber of theRecord & ", " & listingCity of theRecord & " " & listingState of theRecord & " " & listingZipcode of theRecord & quote & " --description=" & quote & listingRemarks of theRecord & quote & " --thumbnail /Users/snaplash/Desktop/SNAPLASH_DO_NOT_DELETE/COMPLETED_DO_NOT_DELETE/" & listingMLSProviderPrefix of theRecord & Mlsid of theRecord & "/Branded/" & listingMLSProviderPrefix of theRecord & Mlsid of theRecord & "_POSTER.png /Users/snaplash/Desktop/SNAPLASH_DO_NOT_DELETE/COMPLETED_DO_NOT_DELETE/" & listingMLSProviderPrefix of theRecord & Mlsid of theRecord & "/Branded/" & listingMLSProviderPrefix of theRecord & Mlsid of theRecord & ".mp4; exit;"
   
   set BrandedIdNumber to result as string
   
   set BrandedYoutubeLink to "https://www.youtube.com/embed/" & BrandedIdNumber
   
   
end run

The script gives a result such as BPlj8UOLgNE as the ID number

What is the best most efficient way to pas this variable to another script?

I was thinking it may just be better to output to a txt file?

Applescript:

do shell script "echo " & BrandedYoutubeLink & " > /Users/snaplash/Desktop/SNAPLASH_DO_NOT_DELETE/PROCESSING_DO_NOT_DELETE/BrandedYTID.txt"

Is this the best way to approach this as I will always know the file name?

Applescript:

set BrandedYoutubeLink to (do shell script "cat /Users/snaplash/Desktop/SNAPLASH_DO_NOT_DELETE/PROCESSING_DO_NOT_DELETE/BrandedYTID.txt | xargs echo")

display dialog BrandedYoutubeLink

Any opinions will be most welcome!

Last edited by snaplash (2017-03-14 10:13:37 am)

Offline

 

#2 2017-03-14 11:15:21 am

DJ Bazzie Wazzie
Member
From: the Netherlands
Registered: 2004-10-20
Posts: 2594

Re: Best way to pass Variable?

Depends on when the other script is called.

Synchronously
When the other script is called by the upload script you can pass variables as an list to the run handler.

Applescript:

script myCount
   on run argv
       return count of argv
   end run
end script

run script myCount with parameters {1, 2, 3, 4}

on the command line you can send multiple parameters just by adding more arguments to the command line but all parameters are strings. When script myCount is saved in myCount.scpt you can call it like:

osascript myCount.scpt 1 2 3 4

Asynchronously

If the script is called by any script and at any given time it's indeed better to store it in a file at an know location. It's much more like shared script data than passing a variable. The examples you wrote are perfectly fine. You can read and write data to files many different ways using the shell, osaxen, cocoa or other application but they're doing all the same thing; using the kernel to read and write data to disk.

Offline

 

#3 2017-03-14 11:24:51 am

snaplash
Member
Registered: 2014-08-21
Posts: 41

Re: Best way to pass Variable?

Thank you so much for the advice!

Yes my scripts run in separate widgets.

I didnt know if writing to file may be a bit clunky, but it seems less clunky than passing info.

Thank you its appreciated!~

Offline

 

Board footer

Powered by FluxBB

[ Generated in 0.038 seconds, 10 queries executed ]

RSS (new topics) RSS (active topics)